datagrid question

G

Guest

I have a form, with multiple tabs. Each tab contains 1 datagrid except for
the last tab which contains 2 datagrids.
I have a toolbar that I use for the entire form. When the 'delete' button is
pressed, and any but the last tab is active, it prompts the user, then
deletes the currently selected row from the focussed datagrid.
My problem lies with the last tab.
I have 2 datagrids on my last tab. I'd like the user to be able to click the
row they want deleted (from either datagrid), then click delete.
I can't figure out how to find out which datagrid is selected. I've posted
here, and other places - must be a tough question :)
TIA!
Amber
 
B

Bart Mermuys

Hi,

amber said:
I have a form, with multiple tabs. Each tab contains 1 datagrid except for
the last tab which contains 2 datagrids.
I have a toolbar that I use for the entire form. When the 'delete' button
is
pressed, and any but the last tab is active, it prompts the user, then
deletes the currently selected row from the focussed datagrid.
My problem lies with the last tab.
I have 2 datagrids on my last tab. I'd like the user to be able to click
the
row they want deleted (from either datagrid), then click delete.
I can't figure out how to find out which datagrid is selected.

You could use something like:

private void OnDeleteClick( ... )
{
Control c = ActiveControl;

while ( c!=null && !(c is DataGrid) )
c = c.Parent;

// if you want to check which DataGrid has focus (if any)
if ( c == dataGrid1 ) ...
if ( c == dataGrid2 ) ...

// if you want to delete the current row of the selected grid
if ( c!=null )
{
DataGrid grd = (DataGrid)c;
CurrencyManager cm = (CurrencyManager)
BindingContext[grd.DataSource, grd.DataMember];

if ( cm.Count > 0 )
{
DataRowView drv = (DataRowView) cm.Current;
drv.Delete();
}
}

HTH,
Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top