how to check/uncheck the checkbox in datagrid

G

Guest

I have datagrid with 5 items. Out of which 1 items are checkboxes. The bool
column(checkbox column ) in added in datagrid. The rest of Data is binded
dynamically to the datagrid

Based on some values from the database I have to check or uncheck the
checkbox in the datatgrid.

i am not able to change the value of checkbox at runtime. Does any one know
how to do this in windows form?
 
V

vijai thoppae

try this For the datagrid you must be having a Datatable. Using the
DataTableObject try this
__DataTable.Rows[RowIndex][ColumnIndex] = true; // ColumnIndex refers to
the checkbox column,RowIndex refers to the corresponding row.

~VJ
 
G

Guest

Dim ts As New DataGridTableStyle()
ts.MappingName = "MyTable"


Dim dc As New DataColumn("MyBoolColumn", GetType(Boolean))
dc.DefaultValue = False
myDS.Tables("MyTable").Columns.Add(dc)

Dim txtID6 As New DataGridBoolColumn()
txtID6.MappingName = "MyBoolColumn"
txtID6.HeaderText = "CHECKBOX"
txtID6.Width = 80
ts.GridColumnStyles.Add(txtID6)

Dim txtID As New DataGridTextBoxColumn()
txtID.MappingName = "MemberID"
txtID.HeaderText = "MemberID"
txtID.Width = 50
ts.GridColumnStyles.Add(txtID)

Dim txtID1 As New DataGridTextBoxColumn()
txtID1.MappingName = "Plan"
txtID1.HeaderText = "Plan"
txtID1.Width = 80
ts.GridColumnStyles.Add(txtID1)

Dim txtID2 As New DataGridTextBoxColumn()
txtID2.MappingName = "Retirement Date"
txtID2.HeaderText = "Retirement Date"
txtID2.Width = 80
ts.GridColumnStyles.Add(txtID2)

Dim txtID3 As New DataGridTextBoxColumn()
txtID3.MappingName = "CaseStatus"
txtID3.HeaderText = "CaseStatus"
txtID3.Width = 80
ts.GridColumnStyles.Add(txtID3)

Dim txtID4 As New DataGridTextBoxColumn()
txtID4.MappingName = "CaseDate"
txtID4.HeaderText = "CaseDate"
txtID4.Width = 80
ts.GridColumnStyles.Add(txtID4)

Dim txtID5 As New DataGridTextBoxColumn()
txtID5.MappingName = "Comments"
txtID5.HeaderText = "Comments"
txtID5.Width = 80
ts.GridColumnStyles.Add(txtID5)

'Dim dc1 As New DataColumn("MyBoolColumn", GetType(Boolean))
'dc1.DefaultValue = False
'myDS.Tables("MyTable").Columns.Add(dc1)

'Dim txtID61 As New DataGridBoolColumn()
'txtID61.MappingName = "MyBoolColumn"
'txtID61.HeaderText = "CHECKBOX"
'txtID61.Width = 50
'ts.GridColumnStyles.Add(txtID61)
'dgCases.TableStyles.Clear()
'dgCases.TableStyles.Add(ts)
'Me.dgCases.DataSource = myDS.Tables(0)

'dgCases.SetDataBinding(myDS, "MyTable")
dgCases.SetDataBinding(myDS, "MyTable")
dgCases.TableStyles.Clear() 'clear the contents for
second try.
dgCases.TableStyles.Add(ts)
dgCases.SetDataBinding(myDS, "MyTable")

vijai thoppae said:
try this For the datagrid you must be having a Datatable. Using the
DataTableObject try this
__DataTable.Rows[RowIndex][ColumnIndex] = true; // ColumnIndex refers to
the checkbox column,RowIndex refers to the corresponding row.

~VJ

I have datagrid with 5 items. Out of which 1 items are checkboxes. The bool
column(checkbox column ) in added in datagrid. The rest of Data is binded
dynamically to the datagrid

Based on some values from the database I have to check or uncheck the
checkbox in the datatgrid.

i am not able to change the value of checkbox at runtime. Does any one know
how to do this in windows form?
 
G

Guest

This is my code. At runtime i am not able to change the value in checkbox.
I am not able to understand ur reply. can u tell me with example or with a
litle bit of code . thanks
Dim ts As New DataGridTableStyle()
ts.MappingName = "MyTable"


Dim dc As New DataColumn("MyBoolColumn", GetType(Boolean))
dc.DefaultValue = False
myDS.Tables("MyTable").Columns.Add(dc)

Dim txtID6 As New DataGridBoolColumn()
txtID6.MappingName = "MyBoolColumn"
txtID6.HeaderText = "CHECKBOX"
txtID6.Width = 80
ts.GridColumnStyles.Add(txtID6)

Dim txtID As New DataGridTextBoxColumn()
txtID.MappingName = "MemberID"
txtID.HeaderText = "MemberID"
txtID.Width = 50
ts.GridColumnStyles.Add(txtID)

Dim txtID1 As New DataGridTextBoxColumn()
txtID1.MappingName = "Plan"
txtID1.HeaderText = "Plan"
txtID1.Width = 80
ts.GridColumnStyles.Add(txtID1)

Dim txtID2 As New DataGridTextBoxColumn()
txtID2.MappingName = "Retirement Date"
txtID2.HeaderText = "Retirement Date"
txtID2.Width = 80
ts.GridColumnStyles.Add(txtID2)

Dim txtID3 As New DataGridTextBoxColumn()
txtID3.MappingName = "CaseStatus"
txtID3.HeaderText = "CaseStatus"
txtID3.Width = 80
ts.GridColumnStyles.Add(txtID3)

Dim txtID4 As New DataGridTextBoxColumn()
txtID4.MappingName = "CaseDate"
txtID4.HeaderText = "CaseDate"
txtID4.Width = 80
ts.GridColumnStyles.Add(txtID4)

Dim txtID5 As New DataGridTextBoxColumn()
txtID5.MappingName = "Comments"
txtID5.HeaderText = "Comments"
txtID5.Width = 80
ts.GridColumnStyles.Add(txtID5)

'Dim dc1 As New DataColumn("MyBoolColumn", GetType(Boolean))
'dc1.DefaultValue = False
'myDS.Tables("MyTable").Columns.Add(dc1)

'Dim txtID61 As New DataGridBoolColumn()
'txtID61.MappingName = "MyBoolColumn"
'txtID61.HeaderText = "CHECKBOX"
'txtID61.Width = 50
'ts.GridColumnStyles.Add(txtID61)
'dgCases.TableStyles.Clear()
'dgCases.TableStyles.Add(ts)
'Me.dgCases.DataSource = myDS.Tables(0)

'dgCases.SetDataBinding(myDS, "MyTable")
dgCases.SetDataBinding(myDS, "MyTable")
dgCases.TableStyles.Clear() 'clear the contents for
second try.
dgCases.TableStyles.Add(ts)
dgCases.SetDataBinding(myDS, "MyTable")
vijai thoppae said:
try this For the datagrid you must be having a Datatable. Using the
DataTableObject try this
__DataTable.Rows[RowIndex][ColumnIndex] = true; // ColumnIndex refers to
the checkbox column,RowIndex refers to the corresponding row.

~VJ

I have datagrid with 5 items. Out of which 1 items are checkboxes. The bool
column(checkbox column ) in added in datagrid. The rest of Data is binded
dynamically to the datagrid

Based on some values from the database I have to check or uncheck the
checkbox in the datatgrid.

i am not able to change the value of checkbox at runtime. Does any one know
how to do this in windows form?
 
V

vijai thoppae

fine.. Try this one
ts.Rows[0]["MyBoolColumn"] = true;
I assume ts refers to DataTable object, "MyBoolColumn" refers to Boolean
Column,"0" refers to 1st row in the grid.

Also add this code as part of the DataGridTableStyle for Boolcolumn to have
2 states true/false rather than 3 states.// Dim txtID6 As New
DataGridBoolColumn()
txtID6.MappingName = "MyBoolColumn"
txtID6.HeaderText = "CHECKBOX"
txtID6.Width = 80
VJ: Dim dgColumn as DataGridBoolColumn dgColumn =
(DataGridBoolColumn)myDGColumnSelect;
This property will set to either true or false state...

VJ: dgColumn.AllowNull = false;

ts.GridColumnStyles.Add(txtID6)




~Vijai
Rekha said:
This is my code. At runtime i am not able to change the value in checkbox.
I am not able to understand ur reply. can u tell me with example or with a
litle bit of code . thanks
Dim ts As New DataGridTableStyle()
ts.MappingName = "MyTable"


Dim dc As New DataColumn("MyBoolColumn", GetType(Boolean))
dc.DefaultValue = False
myDS.Tables("MyTable").Columns.Add(dc)

Dim txtID6 As New DataGridBoolColumn()
txtID6.MappingName = "MyBoolColumn"
txtID6.HeaderText = "CHECKBOX"
txtID6.Width = 80
ts.GridColumnStyles.Add(txtID6)

Dim txtID As New DataGridTextBoxColumn()
txtID.MappingName = "MemberID"
txtID.HeaderText = "MemberID"
txtID.Width = 50
ts.GridColumnStyles.Add(txtID)

Dim txtID1 As New DataGridTextBoxColumn()
txtID1.MappingName = "Plan"
txtID1.HeaderText = "Plan"
txtID1.Width = 80
ts.GridColumnStyles.Add(txtID1)

Dim txtID2 As New DataGridTextBoxColumn()
txtID2.MappingName = "Retirement Date"
txtID2.HeaderText = "Retirement Date"
txtID2.Width = 80
ts.GridColumnStyles.Add(txtID2)

Dim txtID3 As New DataGridTextBoxColumn()
txtID3.MappingName = "CaseStatus"
txtID3.HeaderText = "CaseStatus"
txtID3.Width = 80
ts.GridColumnStyles.Add(txtID3)

Dim txtID4 As New DataGridTextBoxColumn()
txtID4.MappingName = "CaseDate"
txtID4.HeaderText = "CaseDate"
txtID4.Width = 80
ts.GridColumnStyles.Add(txtID4)

Dim txtID5 As New DataGridTextBoxColumn()
txtID5.MappingName = "Comments"
txtID5.HeaderText = "Comments"
txtID5.Width = 80
ts.GridColumnStyles.Add(txtID5)

'Dim dc1 As New DataColumn("MyBoolColumn", GetType(Boolean))
'dc1.DefaultValue = False
'myDS.Tables("MyTable").Columns.Add(dc1)

'Dim txtID61 As New DataGridBoolColumn()
'txtID61.MappingName = "MyBoolColumn"
'txtID61.HeaderText = "CHECKBOX"
'txtID61.Width = 50
'ts.GridColumnStyles.Add(txtID61)
'dgCases.TableStyles.Clear()
'dgCases.TableStyles.Add(ts)
'Me.dgCases.DataSource = myDS.Tables(0)

'dgCases.SetDataBinding(myDS, "MyTable")
dgCases.SetDataBinding(myDS, "MyTable")
dgCases.TableStyles.Clear() 'clear the contents for
second try.
dgCases.TableStyles.Add(ts)
dgCases.SetDataBinding(myDS, "MyTable")
vijai thoppae said:
try this For the datagrid you must be having a Datatable. Using the
DataTableObject try this
__DataTable.Rows[RowIndex][ColumnIndex] = true; // ColumnIndex refers to
the checkbox column,RowIndex refers to the corresponding row.

~VJ

I have datagrid with 5 items. Out of which 1 items are checkboxes. The bool
column(checkbox column ) in added in datagrid. The rest of Data is binded
dynamically to the datagrid

Based on some values from the database I have to check or uncheck the
checkbox in the datatgrid.

i am not able to change the value of checkbox at runtime. Does any one know
how to do this in windows form?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top