Results 1 to 8 of 8

Thread: Adding a chkbox column to datagrid. (its a common q. but pls read.)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    Unhappy 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.
    Anis Bombaywala

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 )

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Do a search on DataGridTableStyle / DataGridColumnStyle.

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

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    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)
    Anis Bombaywala

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width