Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date
Datagridview column sort to date Datagridview column sort to date
Datagridview column sort to date
Go Back  Xtreme Visual Basic Talk > > > Datagridview column sort to date


Reply
 
Thread Tools Display Modes
  #1  
Old 11-11-2007, 01:37 PM
jaap newbie jaap newbie is offline
Junior Contributor
 
Join Date: Feb 2004
Posts: 234
Default Datagridview column sort to date


Hello,

I am trying to sort a column in the datagridview to date. I thought this would do the trick:

Code:
Me.DgvAZLeul.Columns(1).ValueType = GetType(Date)

But this does not work?

What am I doing wrong?

Thanks.
Reply With Quote
  #2  
Old 11-13-2007, 10:53 AM
Jayded Jayded is offline
Centurion
 
Join Date: Jul 2003
Posts: 144
Default

I have been really enjoying sort work in datagridviews. I stumbled across a really cool document written by the manufacturer of the datagridview that has a FAQ that answers a number of questions including sorting.
Take a look and see what you think;
http://windowsclient.net/samples//Go...View%20FAQ.doc
I downloaded the document if you have any problems with the above link.
Reply With Quote
  #3  
Old 11-13-2007, 06:38 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

You need to understand how it (DGV sort) works. In your example you merely assigned to the DGV column the Type Date. Search for "datagridview sort" on the msdn site, there are plenty of examples there to get you going.
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #4  
Old 11-14-2007, 08:29 AM
jaap newbie jaap newbie is offline
Junior Contributor
 
Join Date: Feb 2004
Posts: 234
Default

I'll read the dgv file and check the MSDN site on the dgv sort.

thanks.
Reply With Quote
  #5  
Old 11-23-2007, 09:03 AM
jaap newbie jaap newbie is offline
Junior Contributor
 
Join Date: Feb 2004
Posts: 234
Default

Quote:
Search for "datagridview sort" on the msdn site, there are plenty of examples there to get you going.
Hi can you show me where to find these examples on the msdn site? I did a search and lots of thing about the sort but not really what I'm looking for.

Thanks in advance.
Reply With Quote
  #6  
Old 11-23-2007, 10:43 AM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #7  
Old 11-26-2007, 09:52 AM
jaap newbie jaap newbie is offline
Junior Contributor
 
Join Date: Feb 2004
Posts: 234
Default

Hi there,

Here's a little example of how I solved it (a part of it)

Code:
Public Sub DgvTest() Dim tbl As New DataTable Dim tblRow As DataRow With tbl.Columns .Add("Date").DataType = GetType(System.DateTime) .Add("Test") End With Me.Dgv.DataSource = tbl For i As Integer = 1 To 10 tblRow = tbl.NewRow With tblRow .Item("Date") = i & "-12-2007" .Item("Test") = "Yes" End With tbl.Rows.Add(tblRow) Next For i As Integer = 1 To 10 tblRow = tbl.NewRow With tblRow .Item("Date") = "12-" & i & "-2007" .Item("Test") = "No" End With tbl.Rows.Add(tblRow) Next Dgv.Sort(Dgv.Columns("Date"), System.ComponentModel.ListSortDirection.Descending) End Sub

The only problem is that this uses the date format that the os uses (depends on the country you live in I think).

Is it possible to change this? the the US format for example?
Reply With Quote
  #8  
Old 11-26-2007, 09:21 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

You can use the .DefaultCellStyle.Format property of the DataGridViewColumn to make the dates appear the way you want.
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date Datagridview column sort to date
Datagridview column sort to date
Datagridview column sort to date
 
Datagridview column sort to date
Datagridview column sort to date
 
-->