Hi Dave
You put me on the right track, but the correct way turned out to be this.
dataGridView1.FirstDisplayedScrollingRowIndex =
myTable.Rows.IndexOf(myTable.Rows.Find(myIndex));
dataGridView1.CurrentCell = dataGridView1.FirstDisplayedCell;
/Lennart
"Dave Sexton" <dave@jwa[remove.this]online.com> skrev i meddelandet
news:%(E-Mail Removed)...
> Hi Lennart,
>
> I'm not exactly sure what you are asking, but here is some code that will
> select the row of the DataGridView that is bound to a DataRow with a
> specific primary key value:
>
> int primaryKey = 5;
>
> // assuming dataGridView1 is bound to dataTable
> int rowIndex = dataTable.Rows.IndexOf(dataTable.Rows.Find(primaryKey));
>
> dataGridView1.Rows[rowIndex].Selected = true;
>
> You can replace "dataTable.Rows" with "dataView" in the above code if
> dataView is a DataView to which the DataGridView is bound instead of
> dataTable.
>
> - Dave Sexton
>
> "Lennart" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi
>>
>> I have a DataGridView on a Form filled with data from a DataTable. When
>> I Load this form I want to select a row in the DataGridView depending on
>> a selected Primary Key index;
>>
>> How do I do this?
>>
>> /Lennart
>>
>
>
|