PDA

Click to See Complete Forum and Search --> : Adding a chkbox column to datagrid. (its a common q. but pls read.)


anis_b
Apr 2nd, 2003, 03:31 AM
...this has been a very common question/topic on the net.

and after reading much of that still i am not getting how to do it.

here is my code in brief :

Dim con As New SqlConnection("Data Source=server1;Initial Catalog=Hotel Management;" & _
"Integrated Security=SSPI;")
Dim da As New SqlDataAdapter("roo_Room_Facility_Master_Get", con)
Dim ds As New DataSet("Table1")
da.Fill(ds, "Table1")
Dim dt As DataTable
dt = ds.Tables(0)
DataGrid1.DataSource = dt


the sql procedure returns a list of Facilities that can be provided in a Room thru a Select Query which itself doesnt contain any boolean field.

i want to add an extra checkbox column just for the sake of making multiple selections. so that i can store those selected ids seperated by commas.

please suggest some good article/code which clearly gives the desired solution.

hellswraith
Apr 2nd, 2003, 07:45 AM
You are going to have to add a template column. Then you add a checkbox in that. As far as reading thier values, I am not sure. I will look around because it seems it should be real easy.

Edit:
I just realized that I was in the VB.Net section, not the ASP.Net section. I am not sure about the windows form datagrid....sorry.

Lunatic3
Apr 2nd, 2003, 08:19 AM
Please define more clearly. If you want to add an extra column to your datagrid then this column may be bound or unbound. If you need a bound column you just add a bool column to your 'dt' , and then process its value. The value of this column can depend on other columns. If you like to add an unbound column thats another story.

Pirate
Apr 2nd, 2003, 11:56 AM
Never heard of that . I just heard that you can add combobox to your datagrid not checkbox .(Maybe I have to dig the net more ;) )

DevGrp
Apr 2nd, 2003, 01:13 PM
Checkboxes can be added to. I did it when I bind a table from MSDE to a datagrid and the checkbox column just showed up.

Lunatic3
Apr 2nd, 2003, 01:56 PM
Check boxes for datagrid do exist and called DataGridBoolColumn!

Lethal
Apr 2nd, 2003, 04:52 PM
Do a search on DataGridTableStyle / DataGridColumnStyle.

Gotta run, or I would post some code for you..

anis_b
Apr 4th, 2003, 04:45 AM
Originally posted by Pirate
Never heard of that . I just heard that you can add combobox to your datagrid not checkbox .(Maybe I have to dig the net more ;) )


Dim con As New SqlConnection("Data Source=server1;Initial Catalog=Hotel Management;" & _
"Integrated Security=SSPI;")

Dim da As New SqlDataAdapter("z_Room_Facility_Master", con)
Dim ds As New DataSet("Table1")
da.Fill(ds, "Table1")
dt = ds.Tables(0)
DataGrid1.DataSource = dt

gs.MappingName = ds.Tables(0).TableName

Dim bc As DataGridBoolColumn
bc = New DataGridBoolColumn()
gs.GridColumnStyles.Add(bc)
bc.MappingName = "abc"
bc.HeaderText = "Select"
bc.AllowNull = False

Dim col1 As DataGridTextBoxColumn
col1 = New DataGridTextBoxColumn()
gs.GridColumnStyles.Add(col1)
col1.TextBox.Enabled = False
col1.HeaderText = "Facility_ID"
col1.MappingName = "Facility_ID"

Dim col2 As DataGridTextBoxColumn
col2 = New DataGridTextBoxColumn()
gs.GridColumnStyles.Add(col2)
col2.TextBox.Enabled = False
col2.HeaderText = "Facility"
col2.MappingName = "Facility"

DataGrid1.TableStyles.Add(gs)