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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid CurrentCell.RowNumber / CurrentRowIndex problem ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I've noticed an oddity with the using of a DataGrid component.
If I've got the DataGrid set to have a DataSource of a DataTable that has more than one row in it and I've focused on one of these rows (say row 9 of 10).
If I then empty my DataTable (using dt.Clear();) I then get a problem wirh the Repaint method behind the DataGrid in question when I make an entry in the underlying DataTable such that I have one row in the grid.
The CurrentCell.RowIndex / CurrentRowIndex still maintains the last row position (namely 8) so obviously I get an error when it trys to deal with the DataGrid's row 8. In this case I get a very nasty red cross through the DataGrid that is trying to be repainted.
I've worked around this by resetting the CurrentRowIndex to 0 when I empty the DataTable behind the DataGrid.
Can anyone suggest why I should need to do this ?
If I have no rows in the DataGrid then how can my CurrentRowIndex be 8 still ???
Any thoughts would be appreciated.
Thanks in advance
Steve
 
Are you using the DataGrid in a Window Form or in a Web Form?
Because if you are using the DataGrid in a Web Form you should do DataBind again after emptying the table. If you are using the DataGrid in a Windows Form, you might try to re-initialize the data source for the grid after you emptied the table.
I hope this helps.
 
It's a Windows form - I will follow the suggestion of re-setting the grid's datasource following the emptying of the table.
Thanks for that. :)
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top