Identify selected row in the DataGrids underlying datatable...

  • Thread starter Thread starter Trygve Lorentzen
  • Start date Start date
T

Trygve Lorentzen

Hi,

I need to identify which row is selected in a DataGrid bound to a DataTable.
How do I do this, I'm pretty lost atm and need to make a demo work for
tomorrow. Please help...

Cheers,
Trygve
 
Forgot to mention that this a Windows App and that it doesn't really matter
how I do this as long as I get the Primary key column(s) of the row that is
currently selected (or clicked).
 
Trygve:

You can trap the DataGrid.CurrentCell. CurrentCell has a RowIndex and a
ColumnIndex.

Then, you can use dg.Item(CurrentRowIndex, PrimaryKeyIndex)
 
Thanks for the solution, I guess this is a stupid question, but can I use
any method in the DataTable class to determine what row is currently
selected too? Just like the CurrentCell property of the DataGrid... I
suppose not anyway... It doesn't make sense except for when you loop through
the rows of the datatable in code.

Trygve
 
Trygve:

Unfortunately, a row isn't Selected as such b/c "Selected" is a visual
thing. However, You've got TONS more functionality as far as finding and
referencing things with a DataTable than you do with a grid.

Can you tell me ultimately what you want to do? There's a RowChanging Event
that may be of use, and you can directly reference the rows
DataTable.Rows[WhateverIndex], use Select, Compute and all sorts of other
methods. Let me know that goal and I'll see what I can do.

Cheers,

Bill
 
Back
Top