473,382 Members | 1,752 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,382 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 4808
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...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.