Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

how to check/uncheck the checkbox in datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rekha - 02 Dec 2004 15:23 GMT
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?
vijai thoppae - 02 Dec 2004 15:49 GMT
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
[quoted text clipped - 5 lines]
> i am not able to change the value of checkbox at runtime. Does any one know
> how to do this in windows form?
Rekha - 02 Dec 2004 16:27 GMT
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")

> try this For the datagrid you must be having a Datatable. Using the
> DataTableObject try this
[quoted text clipped - 14 lines]
> know
> > how to do this in windows form?
Rekha - 02 Dec 2004 16:31 GMT
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")

> try this For the datagrid you must be having a Datatable. Using the
> DataTableObject try this
[quoted text clipped - 14 lines]
> know
> > how to do this in windows form?
vijai thoppae - 02 Dec 2004 16:54 GMT
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
> 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
[quoted text clipped - 86 lines]
> > know
> > > how to do this in windows form?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.