Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


VB.Net problem with Datagridview/datatable vs VB6 recordset and datagrid

VB.Net problem with Datagridview/datatable vs VB6 recordset and datagrid

VB.Net problem with Datagridview/datatable vs VB6 recordset and datagrid

All the jobs here seem to want .net skills so I'm trying to learn it by writing one of my vb6 apps in vb.net.

In vb6 I had a datagrid bound to a recordset and using the recordset "find" method it automatically selected that row (if found) AND selected the datagrid row AND set that row to the top of the grid AND put the row marker on that row.
ALSO, you could supply a SQl string to the "Find" method and thus search on any column.

I am tearing my hair out in vb.net... I spent a whole day trying to do this.

In my new vb.net program, I have a datatable bound to a datagridview. I found the datatable.defaultview.find() method BUT it ONLY works on the primary key; luckily it's the primary key I need!
However, try as I might, once that method returns the found row index it DOES NOT set that datagridview row to the top.

I then found I could set the datagridview's "FirstDisplayedScrollingRowIndex" property to the row index returned by the find method and that at least puts the datagrid row of the index from the find method to the top.
BUT... even though the top row now shows the required row, that datarow is not really selected in the datatable or datagrid., because:
1. the row marker does not appear
and 2. the other data related to the current row (displayed in databound textboxes and comboboxes) does not update! it remains the same as before I tried searching for a row.

So- apart from Microsoft making all this way more complicated than vb6 was, is there actually a way to do this or have they made vb.net useless??
Any help welcome.

RE: VB.Net problem with Datagridview/datatable vs VB6 recordset and datagrid

..by the way, I have tried DataGridView1.Rows(pintRowIndex).Selected = True and this does highlight my top grid row,
BUT there is still no row marker and the datatable row is still clearly not selected because the other data bound boxes do not update.

Presumably that missing row marker is why my record row is not selected and updating the other controls.

I would have thought that selecting a row in the grid would mean the row in the bound datatable was also selected, but clearly not- which is very unusable!
In fact I don't understand why the datatable has no way of selecting a current record like in vb6. Only the datagridview can select a row.

Is there a way that is provided in vb.net to make up this functionality that the VB6 version had??

RE: VB.Net problem with Datagridview/datatable vs VB6 recordset and datagrid

Ok today I tried completely different search words in google and finally found this page: https://go4answers.webhost4life.com/Example/datagr...

That suggestion does seem to work and produce the row marker arrow in the left column. The other controls update too, so it seems that unlike vb6, where selecting a row automatically selected the record, you have to do more work. The new terms and methods are not as intuitive as vb6- unless someone tells you what to look for you would never guess.

1. First you have to force a datagridview row to the top so it is visible
2. Then select the row - simply to make it highlighted
3. Then select a CELL ... and that seems to finally set the underlying data row as the "current" row. (even though vb.net does not provide a "current row" in th edata grid.

So all this is required to simply select a data row:

CODE --> vb.net

DataGridView1.FirstDisplayedScrollingRowIndex = pintRowIndex
DataGridView1.CurrentCell = DataGridView1.Rows(pintRowIndex).Cells(0)
DataGridView1.Rows(pintRowIndex).Selected = True 

I hope this helps others who are trying to understand Vb.net and make it do what vb6 did so easily.
Doesn't it seem obvious to Microsoft that if you select a row it's because you want to select a data row so that you can access the data in that row??? (Which VB6 did nicely)

Now to try and get the rest of the features of my design working.
Much steeper learning curve than VB6.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close