[RESOLVED] Selecting a Row in a Datagrid
Hi everyone.
I have a datagridview, which is bound to a Microsoft Access table.
To update parts of the database, I have been changing a the data-bound Text property of a text box, and then calling the following three lines:
Code:
BindingSource.EndEdit();
TableAdapter.Update(DataSet);
TableAdapter.Fill(DataSet.Table);
This works fine, but I have encountered a problem: everytime I call these lines, the currently selected row (only one row may be selected at a time) resets to the first item in the table.
I was planning to store the current row's index in a temp variable, call those lines, then call a method which will re-select the row at that index.
I haven't been able to find a method to achieve this. Dioes someone know how can I select a specific row in a data-bound datagridview?
If there's a better way to do this, by all means let me know.
Thanks,
Qu.
EDIT: Sorry, nearly forgot: I'm using MS Access 2003, Visual C# Express and an OleDb Connection.
Re: Selecting a Row in a Datagrid
Why are you calling Fill? Are there autogenerated values you need to get? This is easier with other databases that support multiple SQL statements in the one command. You can simply get the BindingSource's Position property before the Fill and then reset it afterwards.
Re: Selecting a Row in a Datagrid
Hmmm... that's a good point. I probably don't need to be calling Fill as much as I am.
A few people will be working on the database at a time, so I was using Fill to try to keep it up to date on everyones screen. Perhaps a simple refresh button would be a better way to go.
My ignorance is starting to show. Thanks for the help Jmc.