473,785 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

After DataGrid Sort find Current Row?

Very simple, I have a datagrid on a windows form. I load some rows in it.
I click a column header and it sorts ascending. I click it again it sorts
descending. This is great, but what I want to do is after the sort, I want
to know what row is now the "selected" row. I want to do this so I can
update some stuff on the form that correlates to this row. This does not
seem so easy...please advise.

Thanks,
Ben
Nov 20 '05 #1
6 2005
Hi,

Use the currencymanager to get the row number. If your datagrid is
bound to a dataset.table use the dataset.table.d efaultview to get the
row.

http://www.onteorasoftware.com/downl...redcolumns.zip

Ken
--------------------

"Becker" <be*@benbecker. net> wrote in message
news:#I******** ******@TK2MSFTN GP10.phx.gbl:
Very simple, I have a datagrid on a windows form. I load some rows in it.

I click a column header and it sorts ascending. I click it again it sorts

descending. This is great, but what I want to do is after the sort, I
want
to know what row is now the "selected" row. I want to do this so I can
update some stuff on the form that correlates to this row. This does not

seem so easy...please advise.

Thanks,
Ben


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.3 - Release Date: 6/18/2004
Nov 20 '05 #2
Ken,

I'm confused. The example you pointed me to does the exact same thing I've
got now. When you click, it shows you the name of the current row pre-sort,
but when you let up and it sorts, it doesn't show the name of the post-sort
record that is selected.

What I want is after the sort, the row that is selected, I want to know it's
data values, not the record that used to be there before the sort. Make
sense? I've looked at an answer on syncfusion, and it uses the bindcast
thing, but it doesn't seem to work. I've not seen any working examples of
this. Any ideas?

Thanks,
Ben

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

Use the currencymanager to get the row number. If your datagrid is
bound to a dataset.table use the dataset.table.d efaultview to get the
row.

http://www.onteorasoftware.com/downl...redcolumns.zip

Ken
--------------------

"Becker" <be*@benbecker. net> wrote in message
news:#I******** ******@TK2MSFTN GP10.phx.gbl:
Very simple, I have a datagrid on a windows form. I load some rows in it.
I click a column header and it sorts ascending. I click it again it sorts
descending. This is great, but what I want to do is after the sort, I
want
to know what row is now the "selected" row. I want to do this so I can
update some stuff on the form that correlates to this row. This does not
seem so easy...please advise.

Thanks,
Ben


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.3 - Release Date: 6/18/2004

Nov 20 '05 #3
Hi Ben,

The first question, did you use the dataview as the datasource.

That solves the sort problem mostly, and than use the dataview as the
connection to your tables

I hope this helps?
(And when not reply)

Cor
Very simple, I have a datagrid on a windows form. I load some rows in it.
I click a column header and it sorts ascending. I click it again it sorts
descending. This is great, but what I want to do is after the sort, I want to know what row is now the "selected" row. I want to do this so I can
update some stuff on the form that correlates to this row. This does not
seem so easy...please advise.

Thanks,
Ben

Nov 20 '05 #4
Hi Ben,

The first question, did you use the dataview as the datasource.

That solves the sort problem mostly, and than use the dataview as the
connection to your tables

I hope this helps?
(And when not reply)

Cor
Very simple, I have a datagrid on a windows form. I load some rows in it.
I click a column header and it sorts ascending. I click it again it sorts
descending. This is great, but what I want to do is after the sort, I want to know what row is now the "selected" row. I want to do this so I can
update some stuff on the form that correlates to this row. This does not
seem so easy...please advise.

Thanks,
Ben

Nov 20 '05 #5
Hi,

Made a few changes I added a handler to the dataview list changed
event.

Changes to form load

DataGrid1.DataS ource = ds.Tables("Cate gories")
DataGrid2.DataS ource = ds.Tables("Empl oyees")
AddHandler ds.Tables("Cate gories").Defaul tView.ListChang ed,
AddressOf OnListChanged

Other changes

Private Sub DataGrid1_Mouse Down(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles DataGrid1.Mouse Down
Dim hti As DataGrid.HitTes tInfo = DataGrid1.HitTe st(e.X, e.Y)

If hti.Type = DataGrid.HitTes tType.ColumnHea der Then
'
' Just sorted
'

Trace.WriteLine (DataGrid1.Tabl eStyles(0).Grid ColumnStyles.It em(hti.Column). MappingName)
End If
End Sub

Protected Sub OnListChanged(B yVal sender As Object, ByVal args As
System.Componen tModel.ListChan gedEventArgs)
GetName()
End Sub

Private Sub GetName()
Dim cm As CurrencyManager =
CType(Me.Bindin gContext(DataGr id1.DataSource) , _
CurrencyManager )
Dim drv As DataRowView

drv = ds.Tables("Cate gories").Defaul tView.Item(cm.P osition)
Trace.WriteLine (drv.Item("Cate goryName").ToSt ring)
End Sub

Ken
----------------------
"Becker" <be*@benbecker. net> wrote in message
news:#I******** ******@TK2MSFTN GP11.phx.gbl:
Ken,

I'm confused. The example you pointed me to does the exact same thing
I've
got now. When you click, it shows you the name of the current row
pre-sort,
but when you let up and it sorts, it doesn't show the name of the
post-sort
record that is selected.

What I want is after the sort, the row that is selected, I want to know
it's
data values, not the record that used to be there before the sort. Make

sense? I've looked at an answer on syncfusion, and it uses the bindcast

thing, but it doesn't seem to work. I've not seen any working examples of

this. Any ideas?

Thanks,
Ben

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@b ellsouth.net"vb ***@bellsouth.n et> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

Use the currencymanager to get the row number. If your datagrid is
bound to a dataset.table use the dataset.table.d efaultview to get the
row.

HYPERLINK
"http://www.onteorasoft ware.com/downloads/coloredcolumns. zip"http://www.onte
orasoftware.com/downloads/coloredcolumns. zip

Ken
--------------------

"Becker" <HYPERLINK "mailto:be*@ben becker.net"be*@ benbecker.net> wrote
in message
news:#I******** ******@TK2MSFTN GP10.phx.gbl:

Very simple, I have a datagrid on a windows form. I load some rows
in
it.

I click a column header and it sorts ascending. I click it again it
sorts

descending. This is great, but what I want to do is after the sort,
I
want
to know what row is now the "selected" row. I want to do this so I
can
update some stuff on the form that correlates to this row. This
does
not

seem so easy...please advise.

Thanks,
Ben

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.3 - Release Date: 6/18/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #6
No, thats probably my problem. I use datasource = ds.tables("tabl e")

I will try the ideas I've seen here.

Thanks!
Ben

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Ben,

The first question, did you use the dataview as the datasource.

That solves the sort problem mostly, and than use the dataview as the
connection to your tables

I hope this helps?
(And when not reply)

Cor
Very simple, I have a datagrid on a windows form. I load some rows in it. I click a column header and it sorts ascending. I click it again it sorts descending. This is great, but what I want to do is after the sort, I

want
to know what row is now the "selected" row. I want to do this so I can
update some stuff on the form that correlates to this row. This does not seem so easy...please advise.

Thanks,
Ben


Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
13585
by: aaa | last post by:
Hi I am trying to create a read-only DataGrid that would always have current row selected. Currently, I am using method: public void SelectDataGridRow(DataGrid dg) { if (dg.CurrentRowIndex > -1) { dg.Select(dg.CurrentRowIndex);
2
1724
by: VMI | last post by:
Hi, I have a Windows datagrid that's attached to a filled datatable. The grid also has a tablestyle. Since the data from the grid comes from a datatatable, how can I retrieve the data from a specific table row once a user clicks on a grid row? I already have the code that lets me know what grid row the user clicked on, but, for example, if I want to retrieve the value of the 5th column in the grid, I'm currently using myGrid.ToString()....
4
2843
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the form/grid first opens up and the grid is immediately sorted the TB don't reflect the sorted data of the First row of the grid. Note: Initially the black grid indicator arrow points to the first row. If the user choses another row and then sorts...
1
2353
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current page. i.e. If I have: IntegerValue StringValue CurrencyValue 0 Item 0 0 1 Item 1 1.23
1
1463
by: Jim | last post by:
Hello, I am creating a windows form application using vb.net 2003 which displays data in a datagrid, and then, if the user wants, I produce a nicely formatted crystal report of the data. The question I have is: if I allow the user to sort the datagrid by clicking on the column header, is there any way that I can tell which column the datagrid is sorted on, so that I can sort the data in the crystal report the same way?
3
4224
by: Gene Hubert | last post by:
I'm using DataTable.ImportRow to move data from one datatable to another... Dim dt, dtTarget As DataTable Dim dr As DataRow dt = DirectCast(Me.DataSource, DataTable) dtTarget = dt.Clone 'copy the data structure dtTarget.DefaultView.Sort = String.Empty 'remove the sort
16
2031
by: stojilcoviz | last post by:
I've a datagrid whose datasource is an arraylist object. The arraylist holds many instances of a specific class. I've two questions about this: 1 - Is there a way by which I can obtain a reference to the arraylist item the current row points to? 2 - Is it possible to sort the grid? Many thanks in advance.
10
4956
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 the column order of the datatable). I also allow the user to click on a column header to sort the datagrid by that column. I need to identify the row and column in the datatable when the user clicks on a cell in the datagrid. Using the...
3
2297
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data using data in this row before actually remove it from datagrid. I can certainly control with Delete button. But if I want to allow the user to use Del key on the keyboard, I lost this kind control.
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.