Groups | Blog | Home
all groups > vb.net controls > december 2005 >

vb.net controls : parent-child datagrid ... how to determine if child is shown?


George Hardy
12/22/2005 5:13:48 PM
Hi all,

I have parent/child datagrid (showing transactions and transaction details
when the (+) sign is clicked on the grid.

There is a method to "expand" the row, and an event to fire when you click
"back to parent record", but i see nothing (no property or event) in this
stupid grid to tell me if someone has "expanded" the grid. So, when the
user double-clicks on the row to open the detail form, it has no idea what
row is actually clicked, because the currentrowindex property is still
thinking that it is in parent mode.

is there a work-around for this, or did i completely miss something?

thanks in advance!

george hardy

George Hardy
12/23/2005 9:56:05 AM
it must be just me, it seems a little overly-complicated to get the
CurrentRowIndex for what is actually being shown in the grid.

i did see the datamamber change, thanks...now i can evaluate that if the
user double-clicks on the grid, so i wont get any more "index out of bounds"
crap (from the falsly reported currentrowindex).

gh


[quoted text, click to view]

Bart Mermuys
12/23/2005 1:28:41 PM
Hi,

[quoted text, click to view]

When you bind a DataGrid to a DataTable or DataSet it's internally bound to
a DataView, you can get the current DataRowView from whatever DataView is
currently showing :

DataRowView currentDRV = (DataRowView)
BindingContext[dataGrid1.DataSource, dataGrid1.DataMember].Current;

// ... read fields from currentDRV ...

Notice, that dataGrid1.DataMember changes when you navigate to a child view
or back to a parent view.

HTH,
Greetings


[quoted text, click to view]

Bart Mermuys
12/23/2005 5:51:59 PM
Hi,

[quoted text, click to view]

It's commonly done this way, because a CurrencyManager (which you get from
BindingContext) manages list bindings and therefore have some interesting
properties (regardless of what Control is bound), the code i already showed
you is really a shortcut for :

// because DataGrid.DataMember changes, you'll get
// the right CurrencyManager for the list that's showing
CurrencyManager cm = (CurrencyManager)
BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];

// get position
int position = cm.Position;

// get the list that the DataGrid visually represents which is not
// always the same as the DataSource, but it's always a
// DataView (unless you bound to a custom collection):
DataView dv = (DataView)cm.List;

// get current item:
DataRowView currentDRV = dv[position];

HTH,
Greetings


[quoted text, click to view]

George Hardy
12/27/2005 3:24:59 PM
oh, i get it. I have been trying to avoid as much bound stuff as possible
up to this point. Now, it is all starting to gel upstairs.

thanks a million.!
george


[quoted text, click to view]

AddThis Social Bookmark Button