473,799 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Form Datagrid Checkbox 3 states problem

Below is the code I'm using to dynamically fill a datagrid from a
datatable (fed by an ole connection). Everything is working great
except that my users have to click 2 time on the checkbox to select it,
and if they click on it again it gets greyed out... click on the check
again and then it disapears.

What I want is to be able to be able to:
Click on the box once to check it.
Click on it again to remove the check.

How do you fix this issue?

Dim sql As String = "select A, b, c, d...."

Dim sConnString As String = _
"Provider.. .."
Dim myConnection As New OleDbConnection

dgResults.DataS ource = dt
dt.Columns.Add( "Yes/No", System.Type.Get Type("System.Bo olean"))
dt.Columns.Add( "Number", System.Type.Get Type("System.St ring"))
dt.Columns.Add( "LOT", System.Type.Get Type("System.St ring"))
dt.Columns.Add( "House", System.Type.Get Type("System.St ring"))
dt.Columns.Add( "Node", System.Type.Get Type("System.St ring"))
Dim dr As DataRow
dr = dt.NewRow
Try
myConnection = New OleDb.OleDbConn ection(sConnStr ing)
Dim myCommand As New OleDbCommand(sq l, myConnection)
myConnection.Op en()

Dim myReader As OleDbDataReader = myCommand.Execu teReader
Dim intCounter As Integer = 0
While myReader.Read()
dr = dt.NewRow
dr(0) = False
dr(1) = myReader(0)
dr(2) = myReader(1)
dr(3) = myReader(2)
dr(4) = myReader(3)
dt.Rows.Add(dr)
intCounter += 1
End While
txtCount.Text = CType(intCounte r, String)

myReader.Close( )
myConnection.Cl ose()
myConnection.Di spose()

Catch
Console.Out.Wri teLine("Error: " & Err.Description )
myConnection.Cl ose()
myConnection.Di spose()

End Try

Nov 21 '05 #1
4 4853
Hi,

Here is a datagrid bool column that will prevent the 3rd null state.
Use this column in your datagrid column style.

http://msdn.microsoft.com/library/de...asicprimer.asp
Public Class NoNullBoolColum n

Inherits DataGridBoolCol umn

Protected Overrides Function GetColumnValueA tRow(ByVal lm As
System.Windows. Forms.CurrencyM anager, ByVal row As Integer) As Object

Dim objNull As Object = Convert.DBNull

If objNull.Equals( MyBase.GetColum nValueAtRow(lm, row)) Then

Return False

Else

Return MyBase.GetColum nValueAtRow(lm, row)

End If

End Function

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing. Rectangle, ByVal [readOnly] As Boolean)

If FalseValue.Equa ls(GetColumnVal ueAtRow(source, rowNum)) Then

setcolumnvaluea trow(source, rowNum, TrueValue)

Else

setcolumnvaluea trow(source, rowNum, FalseValue)

End If

End Sub

End Class

Ken

-------------------------
"pmclinn" <pe***@mclinn.c om> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Below is the code I'm using to dynamically fill a datagrid from a
datatable (fed by an ole connection). Everything is working great
except that my users have to click 2 time on the checkbox to select it,
and if they click on it again it gets greyed out... click on the check
again and then it disapears.

What I want is to be able to be able to:
Click on the box once to check it.
Click on it again to remove the check.

How do you fix this issue?

Dim sql As String = "select A, b, c, d...."

Dim sConnString As String = _
"Provider.. .."
Dim myConnection As New OleDbConnection

dgResults.DataS ource = dt
dt.Columns.Add( "Yes/No", System.Type.Get Type("System.Bo olean"))
dt.Columns.Add( "Number", System.Type.Get Type("System.St ring"))
dt.Columns.Add( "LOT", System.Type.Get Type("System.St ring"))
dt.Columns.Add( "House", System.Type.Get Type("System.St ring"))
dt.Columns.Add( "Node", System.Type.Get Type("System.St ring"))
Dim dr As DataRow
dr = dt.NewRow
Try
myConnection = New OleDb.OleDbConn ection(sConnStr ing)
Dim myCommand As New OleDbCommand(sq l, myConnection)
myConnection.Op en()

Dim myReader As OleDbDataReader = myCommand.Execu teReader
Dim intCounter As Integer = 0
While myReader.Read()
dr = dt.NewRow
dr(0) = False
dr(1) = myReader(0)
dr(2) = myReader(1)
dr(3) = myReader(2)
dr(4) = myReader(3)
dt.Rows.Add(dr)
intCounter += 1
End While
txtCount.Text = CType(intCounte r, String)

myReader.Close( )
myConnection.Cl ose()
myConnection.Di spose()

Catch
Console.Out.Wri teLine("Error: " & Err.Description )
myConnection.Cl ose()
myConnection.Di spose()

End Try
Nov 21 '05 #2
Ken,

This template will not work with my code format will it? I'm
dynamically building the checkbox.

-Peter

Nov 21 '05 #3
I added in this code and Ken's class and all I get is on checkbox cell.
How should I modify my prog to take advange of this class? Any help
would be appreciated. I've trying to get this to work for a couple
hours and its driving me crazy.

....myConnectio n.Dispose()

Dim tsGrid As New DataGridTableSt yle
tsGrid.MappingN ame = "dt"

Dim cstYesNo As New NoNullBoolColum n
cstYesNo.AllowN ull = False
cstYesNo.Mappin gName = "YesNo"
cstYesNo.Header Text = "YesNo"
tsGrid.GridColu mnStyles.Add(cs tYesNo)
dgResults.Table Styles.Add(tsGr id)

Nov 21 '05 #4
Answer: ( Private WithEvents dt As New DataTable("dtRe sults"))
Dim tsGrid As New DataGridTableSt yle
tsGrid.MappingN ame = "dtResults"

Dim cstYesNo As New NoNullBoolColum n
cstYesNo.Mappin gName = "YesNo"
cstYesNo.AllowN ull = False
cstYesNo.Header Text = "YesNo"
cstYesNo.Alignm ent = HorizontalAlign ment.Center
tsGrid.GridColu mnStyles.Add(cs tYesNo)
Dim cstNumber As New DataGridTextBox Column
cstNumber.Mappi ngName = "Number"
cstNumber.Heade rText = "Number"
cstNumber.Align ment = HorizontalAlign ment.Center
tsGrid.GridColu mnStyles.Add(cs tNumber)

Dim cstLOT As New DataGridTextBox Column
cstLOT.MappingN ame = "LOT"
cstLOT.HeaderTe xt = "LOT"
cstLOT.Alignmen t = HorizontalAlign ment.Center
tsGrid.GridColu mnStyles.Add(cs tLOT)

Dim cstHouse As New DataGridTextBox Column
cstHouse.Mappin gName = "House"
cstHouse.Header Text = "House"
cstHouse.Alignm ent = HorizontalAlign ment.Center
tsGrid.GridColu mnStyles.Add(cs tHouse)

Dim cstNode As New DataGridTextBox Column
cstNode.Mapping Name = "Node"
cstNode.HeaderT ext = "Node"
cstNode.Alignme nt = HorizontalAlign ment.Center
tsGrid.GridColu mnStyles.Add(cs tNode)

dgResults.Table Styles.Add(tsGr id)

Nov 21 '05 #5

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

Similar topics

5
2640
by: Jean Carlo | last post by:
Hello guys I`m developing a windows form that contain one Datagrid. In this datagrid I insert a checkBox Column. I need to get all rows where checkbox is checked by user. How do I get this rows ? I can´t use the DataSource of Datagrid because I don´t have a Column source for checkBox in my DataSource. Is there any method in datagrid to loop in datagrid rows ?
1
1730
by: RA | last post by:
Hi I wonder if anyone tried this or know if it has been fixed. I am using vs .net 1.1 and have a windows form. In the form I have a DataGrid with the following format: 3 first Columns are of type text box and 5 last columns are of type checkbox(bool) I added some rows info. When the RowHeadersVisible = false here is the problem I see: When launching the application make sure to size down the window so that the
8
1964
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a button that inserts a new row in the SQL table and then refresh the datagrid.
2
1182
by: Raed Sawalha | last post by:
Dear: I have DataGrid , which its task to (Edit, update, and delete) contents of XML File. the structure of XML like this <Info> <Name></Name> <Age></Age>
3
3882
by: Steven | last post by:
How can I disable the ThreeState of a checkbox in a datagrid datacolumn (dataset)? Because of the ThreeState the checkboxes in my datagrid can be in the states 'Checked', 'Unchecked', and 'Indeterminate' (checked + shaded). I want to prevent the checkbox (datacolumn) from getting this last state. How can this be done?? Thanks! Steven
17
7438
by: Mike Fellows | last post by:
im trying (unsucessfully) to add a checkbox column to my datagrid i basically have a datagrid that im populating from a dataset Me.DataGrid1.DataSource = ds.Tables(0) the datagrid then has 5 columns in it but i need to add a sixth column which will be my checkbox column - any help or pointers with this would be great
2
1368
by: RbanBph | last post by:
Hello, I have used datagrid in my web application. I want to set datasource to this datagrid. I want to display check boxes in one of its column. How can i add checkboxes in my datagrid using customtemplate through vb code? Thanks
3
3153
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method expects a DataGridColumn so I instantiated an object of type TemplateColumn that I had hoped I could add a CheckBox to. I soon discovered that the ItemTemplate property of the TemplateColumn class returned an object that had implemented the...
4
7505
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to checkchekboxes and click the Delete button. That will show a confirmation dialog message with the items they choose to delete.
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7571
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.