473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DataGrid with checkboxes

Hi all,

I'm using a datagrid for the first time and I am running into some
problems that I hope someone can help me with. I have a datagrid with
18 rows and 5 columns....column 1 is just text and columns
2-5 are checkboxes. Some of the checkboxes have to be invisible, and
in some cases some of the checkboxes have be be enabled=false. I have
it now so that the entire grid is populated correctly, but I am having
an extremely difficult time figuring out how to do the hiding and
disabling of the checkboxes! I will post the code I am using to
populate the datagrid, and if someone could please help me out by
posting code to hide and disable a checkbox (or even the whole cell) i
would be very grateful. Thank you so much in advance for your help!!!
(dgPermissions is the name of my DataGrid)
Dim dtPermissions As New DataTable("Permissions")

dtPermissions.Columns.Add("Item",
System.Type.GetType("System.String"))

For i = 1 To iNbrCols
dtPermissions.Columns.Add("ColumnName",
System.Type.GetType("System.Boolean"))
Next i

For J = 1 To iNbrRows
dgPermissions.RowTemplate.Height = 18
dgPermissions.RowTemplate.Resizable =
DataGridViewTriState.False
dtPermissions.Rows.Add(New Object() {"Text", False, False,
False, False})
dtPermissions.AcceptChanges()
Next J

dgPermissions.DataSource = dtPermissions

Nov 21 '05 #1
3 1787
Sorry, I meant to replace iNbrCols with 4 and iNbrRows with 18.....they
are variables that are set somewhere else in the program, can be
hardcoded here for this example!

Nov 21 '05 #2
This may seem a little convoluted, but it's the way you have to do it:
Dim tStyle As Windows.Forms.DataGridTableStyle
Dim bCol As Windows.Forms.DataGridBoolColumn
Dim tCol As Windows.Forms.DataGridTextBoxColumn

dgPermissions.DataSource = ds.Tables("Permissions")
tStyle = New Windows.Forms.DataGridTableStyle
tStyle.MappingName = "Permissions"

tCol = New Windows.Forms.DataGridTextBoxColumn
tCol.Width = 105
tCol.NullText = ""
tCol.HeaderText = "Item"
tCol.MappingName = "Item"
tCol.ReadOnly = False
tStyle.GridColumnStyles.Add(tCol)

bCol = New Windows.Forms.DataGridBoolColumn
bCol.Width = 75
bCol.AllowNull = False
bCol.ReadOnly = True
tStyle.GridColumnStyles.Add(bCol)

dgPermissions.TableStyles.Add(tStyle)

Of course, you'll have to add however many boolean columns you want. If you don't want to even see one in the datagrid, just leave it out. If you want the user to be able to change the value, then make readonly=true.

Tom
GatorBait wrote:
Hi all,

I'm using a datagrid for the first time and I am running into some
problems that I hope someone can help me with. I have a datagrid with
18 rows and 5 columns....column 1 is just text and columns
2-5 are checkboxes. Some of the checkboxes have to be invisible, and
in some cases some of the checkboxes have be be enabled=false. I have
it now so that the entire grid is populated correctly, but I am having
an extremely difficult time figuring out how to do the hiding and
disabling of the checkboxes! I will post the code I am using to
populate the datagrid, and if someone could please help me out by
posting code to hide and disable a checkbox (or even the whole cell) i
would be very grateful. Thank you so much in advance for your help!!!
(dgPermissions is the name of my DataGrid)
Dim dtPermissions As New DataTable("Permissions")

dtPermissions.Columns.Add("Item",
System.Type.GetType("System.String"))

For i = 1 To iNbrCols
dtPermissions.Columns.Add("ColumnName",
System.Type.GetType("System.Boolean"))
Next i

For J = 1 To iNbrRows
dgPermissions.RowTemplate.Height = 18
dgPermissions.RowTemplate.Resizable =
DataGridViewTriState.False
dtPermissions.Rows.Add(New Object() {"Text", False, False,
False, False})
dtPermissions.AcceptChanges()
Next J

dgPermissions.DataSource = dtPermissions

Nov 21 '05 #3
Thank you so much Tom!

I tried using the code you provided and when I tried to just add the
columns, it didn't work. I only get a blank DataGrid...do you know
what would cause that?

Also, I'm not so sure I understand fully....once I get the grid set up,
how do I then enable/disable a checkbox?

Thank you again...

Nov 21 '05 #4

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

Similar topics

3
by: john | last post by:
I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the user clicks on a certain button on the page, which is not in the grid, I want to be able to...
2
by: Mortar | last post by:
i have a datagrid with a column of html checkboxes which are created dynamically. The id/name of the checkboxes comes from a value in the database. on a postback, i would like to get all the...
1
by: kannadasan | last post by:
Hi all I am using Datagrid where i place checkboxes in one column with some other columns.The purpose is, if i select the checkboxes and clicks the submit buton Email has to go to the selected...
7
by: DJ Dev | last post by:
Hi All, I have a complex problem. I have dropdownlists (usually 3-5) and the user selects some value from these and for each value selected, datagrids are shown to the user. I am creating the...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
7
by: Jaime Stuardo | last post by:
Hi all.. I have a DataGrid with checkboxes. In the header I have a "check all" checkbox. I'm wondering if there is an easy way to check all checkboxes using that checkbox. I could do it using...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
5
by: rn5a | last post by:
In my application, I want to populate all the directories & files existing in a directory on the server in a DataGrid. To ensure that all the directories get listed first followed by all the files,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.