By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,947 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,947 IT Pros & Developers. It's quick & easy.

How to find out index in sorted datagrid?

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
"Oliver Drobnik" <ne**@drobnik.com> wrote in message
news:ui**************@TK2MSFTNGP09.phx.gbl...
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

Jul 21 '05 #2

P: n/a
This is a common question.
You didn't say WinForms or WebForms, but the answer is similar.

check the archives for some answers,
http://groups.google.com/groups?num=...ex&sa=N&tab=wg

or see here:
http://www.dotnet247.com/247referenc...27/136399.aspx
http://weblogs.asp.net/dmarsh/posts/646.aspx

-Dino
Microsoft
"Oliver Drobnik" <ne**@drobnik.com> wrote in message
news:ui**************@TK2MSFTNGP09.phx.gbl...
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

Jul 21 '05 #3

P: n/a
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

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.