How to find out index in sorted datagrid?

O

Oliver Drobnik

Hi,

I have a datagrid bound to a datatable. Now if I sort the datagrid by
clicking on one of the column heads I can no longer use the index in the
datagrid to find the corresponding row in the datagrid.

How can I find out the new (sorted) index if I know the row in the
datatable?

kind regards
Oliver Drobnik
 
W

William Ryan

Oliver:

If you are using a bound grid the position doesn't matter. The grid just
serves as a UI for the datatable, but whatever changed you make to the grid
will be reflected in the underlying datatable or dataset. As such, you can
determine the current cell of the grid if there is on by using
dataGrid.CurrentCell. Now you know what row and column you are in. With
this known, you can grab whatever value you may want out of the grid or do
just about anything.

Let me put it this way...unless I'm missing your point. If I know that say
"Ryan" originally appears as the last name in my datatable in Row2 column0
and then the grid is sorted. Now, "Ryan" appears at row 100 column0. I can
still do anything I need to with that field and record, so where it appears
in the actual datatable isn't all that important.

If I misunderstood what you need though, please let me know.

Bill
 
O

Oliver Drobnik

Sorry, if my question was imprecise. I am talking about WinForms.

Ok, I have a datatable:
ID Name
0 A
1 B
2 C
3 D

I bind a datagrid to this dataset.

I sort by name descending, so the datagrid displays:
ID Name
3 D
2 C
1 B
0 A

How do I find out which line in the datagrid has the row with Name "B" or ID
1?



If I get the dataview of the grid like this:

Dim dv As DataView = CType(CType(BindingContext(UsageSet1, "UsageNeu"),
CurrencyManager).List, DataView)

It seems that this view never reflects the current sort order.



kind regards

Oliver Drobnik
 

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

Top