Adding a chkbox column to datagrid. (its a common q. but pls read.)
...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.
hey... it worked with this code..
Quote:
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)