Solved

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

Posted on 2010-09-16
10
726 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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
 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …

685 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