I want to be able to programatically select a newly added row that was added in another screen and not directly in the Grid. So the user can have a visual reference that a post was successful.
I found this answer here:
http://www.akadia.com/services/dotnet_find_methods.html
but it requires your tables to have primary keys and just my luck none of my tables have primary keys. By the way I didn't create these tables. How do I do the find without primary keys? I don't want to have to add them to all my Tables. My tables do have Unique Identity columns and I use the "select scope_identity()..." to return the new ID but I am unable to use this new ID the select it from the Grid.
Loading
Hirendra SisodiyaPosted Apr 23, 2010, 4:59 AM
Hello Donelly
i dont know how you are add new row in DataGridView...
But you do this like
you need to know index of newly added row suppose that if your new row always add in the last position then you can usethiscode:
int Index;
Index = dataGridView1.Rows.Count-1;
dataGridView1.Rows[Index].Selected = true;
// otherwise you need to findout that index
thanks
please mark as answere if it helps
Hirendra SisodiyaPosted Apr 24, 2010, 12:47 AM
now you are doing right.........great..
thanks
Donnelly JamesPosted Apr 23, 2010, 11:07 AM
for ( int i = 0; i < GridContact.Rows.Count; i++ )
{
if ((int)GridContact.Rows[i].Cells[1].Value == ID )
{
GridContact.ClearSelection();
GridContact.Rows[i].Selected = true;
}
}
Thanks to Hirenda for leading me in the right direction.
Donnelly JamesPosted Apr 23, 2010, 9:26 AM