Solved

Sorting a boolean column in datagridview +vb.net 2005 windows programming

Posted on 2010-09-16
10
717 Views
Last Modified: 2013-11-07
Hi,
I am struggling on how to sort a boolean column in datagridview.
When grid is bound with datatable the column has no value in it.Now when I check the row the item value of the boolean column value  is true and when uncheck it the value gets false.
When the column is sorted it sorts by the false and blank value.This is a problem how do I make blank and false same when sorted.Any suggestions?
0
Comment
Question by:RIAS
  • 6
  • 4
10 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33690814
1.What do you mean with Blank Value
2.Set the ThreeState of datagridviewCheckBoxColumn to false
me.DatagridviewCheckBoxColumn.ThreeState=False
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33690893
Otehr Question ..Isn't the column contains CheckBoxes A DatagridView CheckBoxColumn?
0
 

Author Comment

by:RIAS
ID: 33691433
Hi,
No its a not a checkbox column it is a

dtTemp.Columns.Add("Selection", GetType(Object))
so it has a false or true value as I didnt want he checkboxes to appear in the column I created a column like the above.
 
0
 

Author Comment

by:RIAS
ID: 33691447
Blank Value is dbnull value
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33691679
I think that the column add method requires string,string
Me.datagriview1.Columns.Add("ColumnName" as string,HeaderText as string)
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:RIAS
ID: 33692051
But how do you add a object column to datatable.Isn't this the way
dtTemp.Columns.Add("Selection", GetType(Object))  
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33692211
a sory it is a datatable...
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33699027
Other way is to sort in a default View before populate the datagridview...
Try the Function Below


ortDataTable(YourDataTable, B,"YourColumnName", True)
Private Function SortDataTable(ByVal dTable As DataTable, ByVal ColumnName As String, Optional ByVal OrderByAsc As Boolean = True) As DataView

Dim dView As New DataView(dTable)



If OrderByAsc Then

dView.Sort = ColumnName & " ASC"

Else

dView.Sort = ColumnName & " DESC"

End If



Return dView

End Function

Open in new window

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33699041
also try
Me.DataGridView1.Sort(Me.DataGridView1.Columns("SortCol"), System.ComponentModel.ListSortDirection.Ascending)
0
 

Author Closing Comment

by:RIAS
ID: 33699504
Cheers!!!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Web appliction 7 47
LINQ - C# to VB convertion 12 46
Javascript and Jquery not firing 9 39
Get Client IP on RDS - VB.NET 15 25
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now