|
-
Apr 2nd, 2003, 04:31 AM
#1
Thread Starter
Lively Member
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.
-
Apr 2nd, 2003, 08:45 AM
#2
PowerPoster
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.
-
Apr 2nd, 2003, 09:19 AM
#3
Frenzied Member
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.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 2nd, 2003, 12:56 PM
#4
Sleep mode
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 )
-
Apr 2nd, 2003, 02:13 PM
#5
Frenzied Member
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.
Dont gain the world and lose your soul
-
Apr 2nd, 2003, 02:56 PM
#6
Frenzied Member
Check boxes for datagrid do exist and called DataGridBoolColumn!
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Apr 2nd, 2003, 05:52 PM
#7
PowerPoster
Do a search on DataGridTableStyle / DataGridColumnStyle.
Gotta run, or I would post some code for you..
-
Apr 4th, 2003, 05:45 AM
#8
Thread Starter
Lively Member
hey... it worked with this code..
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|