473,473 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataGrid - Sorting Columns

How do I sort a DataGrid Column in code without clicking on the column header?
--
Dennis in Houston
Nov 21 '05 #1
8 1816
Bind to a dataview and set it's Sort property to whatever field you want.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
How do I sort a DataGrid Column in code without clicking on the column header? --
Dennis in Houston

Nov 21 '05 #2
You can use one line of code to create a dataview from the datatable.

Dim dv as DataView = WhateverDataTable.DefaultView

Now, bind the grid to the view instead of the table. All of your
current
functionality will still be in tact.

You can call Sort on any field in the dataview and sort it which will
cause
the grid to sort.You could offer this via a context menu for instance,
if
for some reason you didn't want to allow sorting based on the grid
headers.

http://www.knowdotnet.com/articles/dataviewsort.html
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com:
How do I sort a DataGrid Column in code without clicking on the column
header?


Nov 21 '05 #3
Sorry Bill I had not seen you post your answer yet.

"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:ud**************@TK2MSFTNGP11.phx.gbl:
Bind to a dataview and set it's Sort property to whatever field you
want.


Nov 21 '05 #4
Thanks.

"W.G. Ryan eMVP" wrote:
Bind to a dataview and set it's Sort property to whatever field you want.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
How do I sort a DataGrid Column in code without clicking on the column

header?
--
Dennis in Houston


Nov 21 '05 #5
Is there someother way such as sending a message to the DAtaGrid via WinProc
to sort a column? I don't see where the DataView works with DataSets.

"scorpion53061" wrote:
You can use one line of code to create a dataview from the datatable.

Dim dv as DataView = WhateverDataTable.DefaultView

Now, bind the grid to the view instead of the table. All of your
current
functionality will still be in tact.

You can call Sort on any field in the dataview and sort it which will
cause
the grid to sort.You could offer this via a context menu for instance,
if
for some reason you didn't want to allow sorting based on the grid
headers.

http://www.knowdotnet.com/articles/dataviewsort.html
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com:
How do I sort a DataGrid Column in code without clicking on the column
header?


Nov 21 '05 #6
Not tested, but how about something like this:

dim dv As New DataView
dv = ds.Tables(0).DefaultView 'where ds is the dataset in question
dv.Sort = "Order" 'where Order is the column name by which you want to sort
Me.DataGrid1.DataSource = dv
Me.DataGrid1.Refresh()

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
Is there someother way such as sending a message to the DAtaGrid via
WinProc
to sort a column? I don't see where the DataView works with DataSets.

"scorpion53061" wrote:
You can use one line of code to create a dataview from the datatable.

Dim dv as DataView = WhateverDataTable.DefaultView

Now, bind the grid to the view instead of the table. All of your
current
functionality will still be in tact.

You can call Sort on any field in the dataview and sort it which will
cause
the grid to sort.You could offer this via a context menu for instance,
if
for some reason you didn't want to allow sorting based on the grid
headers.

http://www.knowdotnet.com/articles/dataviewsort.html
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com:
> How do I sort a DataGrid Column in code without clicking on the column
> header?


Nov 21 '05 #7
Talkin about dataview object. Recently I tried to edit some row like this
.... dr(indexcolumn) (indexrow) = "... " .. it was applied to the dataset,
But it didn't update to the datasource when i call
DataAdapter.update(Dataset,"TableName") { this with assumtion that
commandbuilder had been generated }. And also a mistake when i tried to
delete row using dataview object. But it didn't show any error message when
i put the -update method- in try ... catch ... endtry ....
Felling frustated with dataview object .. i used datatable object to edit
and delete row. ... Did u guys have this kind of problems before ?

Martin

"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
Not tested, but how about something like this:

dim dv As New DataView
dv = ds.Tables(0).DefaultView 'where ds is the dataset in question
dv.Sort = "Order" 'where Order is the column name by which you want to sort Me.DataGrid1.DataSource = dv
Me.DataGrid1.Refresh()

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
Is there someother way such as sending a message to the DAtaGrid via
WinProc
to sort a column? I don't see where the DataView works with DataSets.

"scorpion53061" wrote:
You can use one line of code to create a dataview from the datatable.

Dim dv as DataView = WhateverDataTable.DefaultView

Now, bind the grid to the view instead of the table. All of your
current
functionality will still be in tact.

You can call Sort on any field in the dataview and sort it which will
cause
the grid to sort.You could offer this via a context menu for instance,
if
for some reason you didn't want to allow sorting based on the grid
headers.

http://www.knowdotnet.com/articles/dataviewsort.html
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com:
> How do I sort a DataGrid Column in code without clicking on the column > header?


Nov 21 '05 #8
Yes I did. I added beginedit and endedit and the problems were gone. I
thought begin/endedit was optional but it looks like it is obliged.
Frank

"Martin" <ma***************@jusufind.com> wrote in message
news:OM**************@TK2MSFTNGP15.phx.gbl...
Talkin about dataview object. Recently I tried to edit some row like this
... dr(indexcolumn) (indexrow) = "... " .. it was applied to the dataset,
But it didn't update to the datasource when i call
DataAdapter.update(Dataset,"TableName") { this with assumtion that
commandbuilder had been generated }. And also a mistake when i tried to
delete row using dataview object. But it didn't show any error message when i put the -update method- in try ... catch ... endtry ....
Felling frustated with dataview object .. i used datatable object to edit
and delete row. ... Did u guys have this kind of problems before ?

Martin

"William LaMartin" <la******@tampabay.rr.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
Not tested, but how about something like this:

dim dv As New DataView
dv = ds.Tables(0).DefaultView 'where ds is the dataset in question
dv.Sort = "Order" 'where Order is the column name by which you want to

sort
Me.DataGrid1.DataSource = dv
Me.DataGrid1.Refresh()

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
Is there someother way such as sending a message to the DAtaGrid via
WinProc
to sort a column? I don't see where the DataView works with DataSets.

"scorpion53061" wrote:

> You can use one line of code to create a dataview from the datatable.
>
> Dim dv as DataView = WhateverDataTable.DefaultView
>
> Now, bind the grid to the view instead of the table. All of your
> current
> functionality will still be in tact.
>
> You can call Sort on any field in the dataview and sort it which will
> cause
> the grid to sort.You could offer this via a context menu for instance,> if
> for some reason you didn't want to allow sorting based on the grid
> headers.
>
> http://www.knowdotnet.com/articles/dataviewsort.html
>
>
> "Dennis" <De****@discussions.microsoft.com> wrote in message
> news:10**********************************@microsof t.com:
> > How do I sort a DataGrid Column in code without clicking on the column> > header?
>
>



Nov 21 '05 #9

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

Similar topics

0
by: Kshitij | last post by:
Hi, I'm having a datagrid. I'm addng the columns at runtime to the datagrid.But the problem comes during sorting.It doesn't enable the sort column link.Any help on this. Here is my code. ...
2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
2
by: Hajime Kusakabe | last post by:
Hi. I have created a datagrid (datagrid1) without any columns on a aspx page. Then aspx.vb adds columns from a database. It is somthing like this .... ================================== Dim...
0
by: Robert Brinson | last post by:
Hello all! I'm running .NET Framework 1.1 using VS.NET 2003. I've got a mystery with a DataGrid. Below is the definition of the DataGrid from my aspx page: </asp:datagrid><asp:datagrid...
2
by: Mike P | last post by:
I have just written my first page with a datagrid that allows ASC and DESC sorting. But I want to know how I can get it so that the header shows the type of sorting that has just been done on it...
1
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...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
2
by: saleek | last post by:
Hi, I am trying to figure out why my datagrid has stopped firing the page and sort commands. Scenario: I originally had template columns in my datagrid and had set up custom bi-directional...
1
by: ECD | last post by:
Hello all, I can usually find solutions to my .NET problems by searching these groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0 framework). I want to disable sorting on...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.