Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 769
  • Last Modified:

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

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
RIAS
Asked:
RIAS
  • 6
  • 4
1 Solution
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
1.What do you mean with Blank Value
2.Set the ThreeState of datagridviewCheckBoxColumn to false
me.DatagridviewCheckBoxColumn.ThreeState=False
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Otehr Question ..Isn't the column contains CheckBoxes A DatagridView CheckBoxColumn?
0
 
RIASAuthor Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
RIASAuthor Commented:
Blank Value is dbnull value
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
I think that the column add method requires string,string
Me.datagriview1.Columns.Add("ColumnName" as string,HeaderText as string)
0
 
RIASAuthor Commented:
But how do you add a object column to datatable.Isn't this the way
dtTemp.Columns.Add("Selection", GetType(Object))  
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
a sory it is a datatable...
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
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
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
also try
Me.DataGridView1.Sort(Me.DataGridView1.Columns("SortCol"), System.ComponentModel.ListSortDirection.Ascending)
0
 
RIASAuthor Commented:
Cheers!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now