More DataGrid Problems

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hello all:

I understand now how to get the current item from the BindingContext of
a DataGrid but it returns the wrong item selected if the columns are
sorted. For instance, if I have a list of employees and they are filled
into a DataGrid everything works fine when I select one and grab the
info for that selection. But if you reorder a column say by last name
or something it doesn't reorder the binding context associated with the
selection and as such does not return the correct item selected in the
grid. Am I doing something wrong here?

Thanks,

- John -
 
You just want the currently selected row?

Use the CurrentRowIndex property.

in my app, my DataGrid is DataSourced to a DataView so I get the current
DataRow like this:

DataRow row = myDataView[myDataGrid.CurrentRowIndex].Row;
 
Well, here is the scenario. I have a form with a datagrid and a whole
lot of other controls. The other controls are bound so that info from a
db is displayed. What I want to do is have it so when an item is
selected in the datagrid all this info shows up in the other controls as
well. Plus, when you hit the headers on the grid to sort in a different
order, still be able to display the right data.
 
John,

In this case, you should create a data view manually, and bind the grid and
the rest of controls to the very same dataview.
This way, all the bound controls should be served by the same currency
manager and all changes to the current position should be reflected by all
of the controls.

As far as I remember, one has to be sure to use the same data source and
data member names when binding the controls to ensure the same instance of
CurrencyManager is used for all of them.
 
That was exactly my problem and thanking for shining some light on it.
I will give your suggestion a try.

Thanks,

- John -
 
Back
Top