Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Yorkshireman2

Programmer
Jan 21, 2005
154
0
0
CA
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.
 
..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??
 
Ok today I tried completely different search words in google and finally found this page:
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:
DataGridView1.FirstDisplayedScrollingRowIndex = pintRowIndex
DataGridView1.Refresh()
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top