Dynamic ComboBox in DataGridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DEC
    New Member
    • Nov 2007
    • 1

    Dynamic ComboBox in DataGridView

    I have a VB application that's about 95% done. As usual, it's that last 5% that's got me stymied. The program is a Bill-of-material update program that interfaces with an SAP database. The BOM's relate to custom computer configurations. By the nature of a BOM, there are many lines, with many fields to each line. The program uses a DataGridView control to present the data. It is currently working ok with manually-keyed input. However, to make it user-friendly, it needs to use ComboBox dropdowns for the various selections. Therefore, several of the DataGridView columns need to include a combo box. This is where my problem lies.

    Specifically, I have two issues: (1) getting the combo-box to populate from an SQL statement, and (2) getting subsequent combo-boxes on the same line to tailor their content based on the previous combo-box. To illustrate the second issue, if the first combo-box says that this particular row deals with data storage for the computer, then the only items that should be included in the second combo box would be those that are disk drives. Obviously, the selection and content of a control on one BOM line will be completely different from those on other rows.

    I am able to dynamically load a standalone ComboBox, by setting the Display, Value, and DataSource (which returns a table) properties. However, I can't seem to accomplish this when the ComboBox is embedded in a DataGridView control.

    Any help would be greatly appreciated.
    Dave
  • G Satish Kumar
    New Member
    • Nov 2007
    • 8

    #2
    Is your problem to get the combo box in the DataGridView?

    If this is the issue I feel the below code could help you.

    After

    dataadapter.fil l(dataset)

    if the column name is empGrade and this is the first column for which you require the column in the grid view as combo box then

    dim colempgrade as new datagridviewcom boboxcolumn

    colempgrade.dat apropertyname=d ataset.tables(0 ).column(0).toS tring()
    colempgrade.nam e="employee grade"
    colempgrade.dat asource='use the column name or list yyou want to populate the combo
    datagridview.ad d.columns(colem pgrade)

    Please ignore if this not what was not required

    Satish

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      What is the version of VB that you are using?
      Last edited by Killer42; Nov 8 '07, 07:17 AM.

      Comment

      • G Satish Kumar
        New Member
        • Nov 2007
        • 8

        #4
        Originally posted by debasisdas
        What is the version of VB that you are using.
        .NET 2005 is the version I am talking about. I think we have datagridview from 2005 only, the earlier version had only datagrid which lacked some of the enhancements compared to that of DGV.

        Please check if you are using the same version I could give you the exact code for the requirement.

        Satish

        Comment

        Working...