469,593 Members | 1,987 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,593 developers. It's quick & easy.

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 1804
Hi,

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

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

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

"Becker" <be*@benbecker.net> wrote in message
news:#I**************@TK2MSFTNGP10.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***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

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

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

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

"Becker" <be*@benbecker.net> wrote in message
news:#I**************@TK2MSFTNGP10.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.DataSource = ds.Tables("Categories")
DataGrid2.DataSource = ds.Tables("Employees")
AddHandler ds.Tables("Categories").DefaultView.ListChanged,
AddressOf OnListChanged

Other changes

Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(e.X, e.Y)

If hti.Type = DataGrid.HitTestType.ColumnHeader Then
'
' Just sorted
'

Trace.WriteLine(DataGrid1.TableStyles(0).GridColum nStyles.Item(hti.Column).MappingName)
End If
End Sub

Protected Sub OnListChanged(ByVal sender As Object, ByVal args As
System.ComponentModel.ListChangedEventArgs)
GetName()
End Sub

Private Sub GetName()
Dim cm As CurrencyManager =
CType(Me.BindingContext(DataGrid1.DataSource), _
CurrencyManager)
Dim drv As DataRowView

drv = ds.Tables("Categories").DefaultView.Item(cm.Positi on)
Trace.WriteLine(drv.Item("CategoryName").ToString)
End Sub

Ken
----------------------
"Becker" <be*@benbecker.net> wrote in message
news:#I**************@TK2MSFTNGP11.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***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

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

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

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

"Becker" <HYPERLINK "mailto:be*@benbecker.net"be*@benbecker.net> wrote
in message
news:#I**************@TK2MSFTNGP10.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("table")

I will try the ideas I've seen here.

Thanks!
Ben

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by VMI | last post: by
4 posts views Thread by Steve B. | last post: by
1 post views Thread by Jeremy | last post: by
3 posts views Thread by Gene Hubert | last post: by
16 posts views Thread by stojilcoviz | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.