Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Specify comboboxcolumn for bound datatable column

Specify comboboxcolumn for bound datatable column

Scheduled Pinned Locked Moved C#
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drinkingbird
    wrote on last edited by
    #1

    I have a datatable as the datasource for a datagridview. One of the columns displays IDs for another datatable (this relationship is specified in the dataset). Is there any way to specify that this column should be a comboboxcolumn, bound to the related table, rather than just a textboxcolumn?

    X 1 Reply Last reply
    0
    • D drinkingbird

      I have a datatable as the datasource for a datagridview. One of the columns displays IDs for another datatable (this relationship is specified in the dataset). Is there any way to specify that this column should be a comboboxcolumn, bound to the related table, rather than just a textboxcolumn?

      X Offline
      X Offline
      Xint0
      wrote on last edited by
      #2

      Yes there is. Use the DataGridView designer to modify the properties for the column. Also try using a BindingSource (bound to your DataSet) as the data source for the DataGridView. That way you can bind the DataGridView rows to one table and the ComboBoxColumn drop-down to another table easily through the designer.

      - Xint0

      D 1 Reply Last reply
      0
      • X Xint0

        Yes there is. Use the DataGridView designer to modify the properties for the column. Also try using a BindingSource (bound to your DataSet) as the data source for the DataGridView. That way you can bind the DataGridView rows to one table and the ComboBoxColumn drop-down to another table easily through the designer.

        - Xint0

        D Offline
        D Offline
        drinkingbird
        wrote on last edited by
        #3

        The table is dynamically generated, so not really accessible to the designer. I'm not sure how I'd use the BindingSource alternative. Is there a good tutorial or some such on how I might do this? Thanks. -- modified at 23:57 Thursday 2nd November, 2006 Maybe I should be more specific. I have a table of employees, and a table of shifts available to work. There is a table which links the 2 via foreign keys to represent a many-to-many relationship. For easier editing, I create a custom datatable at runtime, where each column represents one of the shifts, and there is one column for specifying the employee's ID. I would like the employee ID column to be a combobox column with the combobox values taken from the employee table (ValueMember = id, DisplayMember = name). Currently, after creating the custom table, I assign it as the datasource of a datagridview, but the default situation is that the column is simply displayed as a textboxcolumn. Is there a way (outside of the designer), to easily do this (I'm still looking into the bindingsource option)? Any help would be appreciated, this has really got me stumped.

        D 1 Reply Last reply
        0
        • D drinkingbird

          The table is dynamically generated, so not really accessible to the designer. I'm not sure how I'd use the BindingSource alternative. Is there a good tutorial or some such on how I might do this? Thanks. -- modified at 23:57 Thursday 2nd November, 2006 Maybe I should be more specific. I have a table of employees, and a table of shifts available to work. There is a table which links the 2 via foreign keys to represent a many-to-many relationship. For easier editing, I create a custom datatable at runtime, where each column represents one of the shifts, and there is one column for specifying the employee's ID. I would like the employee ID column to be a combobox column with the combobox values taken from the employee table (ValueMember = id, DisplayMember = name). Currently, after creating the custom table, I assign it as the datasource of a datagridview, but the default situation is that the column is simply displayed as a textboxcolumn. Is there a way (outside of the designer), to easily do this (I'm still looking into the bindingsource option)? Any help would be appreciated, this has really got me stumped.

          D Offline
          D Offline
          drinkingbird
          wrote on last edited by
          #4

          I finally figured it out. I create the comboboxcolumn before binding to the datatable, bind the column to the employee table, and set its DataPropertyName to the name of the custom table's employee ID column name, and the column from the datatable gets pushed into it.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups