473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to find out index in sorted datagrid?

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
3 4805
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sam | last post by:
Hello group, The datagrid is sorted using a dataview. Can I get the sorted dataview or table from the datagrid or any other way. All I need to get is the sorted data. Here is my code and what I am...
4
by: Tom | last post by:
Hi, I need some help with stl maps. I am using a std::map that is sorted in a very special way. Therefore I am using my own sort function. That works fine. But this is only half the problem....
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
4
by: Arjen | last post by:
Hi, I need to add this inside an array: 1 3 2 4 3 2 4 5 5 1 I think of using this:
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
3
by: Rich | last post by:
Hello, If my datagrid is based on a dataTable (t1) and the currency manager is also bound to t1 and I do a find on a key dim dRow As DataRow, t1 As DataTable .... dRow = t1.Rows.find(somekey)...
4
by: Aaron Smith | last post by:
Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1,...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
3
by: Oliver Drobnik | last post by:
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.