[VB .NET] DataGridView with different combobox members

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akal483
    New Member
    • Jul 2007
    • 8

    [VB .NET] DataGridView with different combobox members

    Hi,
    I have a datagridview which has 3 columns.
    Product : textBox
    Suplier : comboBox
    Price : textBox

    Everytime I add a product to Product column, I want to have the list of supliers that can supply the product in the combobox.

    At this moment I can do this in Visual Basic 2005, but the comboBox list all the supliers instead of only the supliers that can supply a certain product.

    Could someone give me an example how to do this?

    regards
    AL
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by akal483
    Hi,
    I have a datagridview which has 3 columns.
    Product : textBox
    Suplier : comboBox
    Price : textBox

    Everytime I add a product to Product column, I want to have the list of supliers that can supply the product in the combobox.

    At this moment I can do this in Visual Basic 2005, but the comboBox list all the supliers instead of only the supliers that can supply a certain product.

    Could someone give me an example how to do this?

    regards
    AL
    how are you populating the combobox???What is the select query if any you are using????

    Comment

    • akal483
      New Member
      • Jul 2007
      • 8

      #3
      Thank you for your reply.
      I am using unbound datagridviewcom boboxcolumn for suplier column.
      But since it is datagridviewcom boboxcolumn, I only can assign once for all rows. (Store Procedure from SQL Server as source for this combo)

      I don't have any idea, how to solve this problem.

      regards,
      AL

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        I believe that you need to change the stored procedure. Here is an article that may help:
        Running Stored Procedures with ASP.NET

        Comment

        • akal483
          New Member
          • Jul 2007
          • 8

          #5
          Hi Kenobewan, thank you for your guidance.
          At this moment my problem is how to make suplier combobox has different list in every row. I want suplier lists that related with a certain product instead of providing all the supliers.
          Let say "product A" only has "Suplier B", "Suplier D" and "Suplier E",
          "Product B" only has "Suplier A", "Suplier C", and
          "Product C" only has "Suplier B", "Suplier D".
          I can provide store procedure for this, but I don't know how to put this different datas in datagridviewcom boboxcolumn.

          regards
          AL

          Comment

          • jinnee
            New Member
            • Jul 2007
            • 11

            #6
            When user leaves Product cell, we will load all suppliers who supply that product and assign that collection to corresponding Combobox cell.
            We will do all steps in CellLeave() method of DataGridView.

            Hope help.

            Comment

            • akal483
              New Member
              • Jul 2007
              • 8

              #7
              Hi Jinnee,
              I assume that you suggest me to use datagridcombobo xcell.
              Is that right?
              I would appreciate if you could give me an example how to add datagridcombobo xcell with different items to the datagridview.

              Comment

              • RoninZA
                New Member
                • Jul 2007
                • 78

                #8
                Howdy -

                I kinda understand the problem - you want to change the data populated in a specific drop down cell of a datagridview?

                It's actually fairly simple, if you use a bit of OO principles... Here's what you need to do: For every new row that is added (or wherever you want the supplier list to be populated), declare a new DataGridViewCom boBoxCell, which you then populate with your list of suppliers as you would anormal combobox (using the .Items.Add() method). Then, once loaded, set the cell of the row you are working with equal to the new DataGridViewCom boBoxCell...
                Code:
                myDataViewGrid.Rows[myDataViewGrid.Rows.Count - 1].Cells["colSuppliers"] = myNewDataGridViewComboBoxCell
                I don't know if you can easily cast objects in VB, but in C# the really easy way is to cast the existing cell while using it, as follows:
                Code:
                ((DataGridViewComboBoxCell)myDGV.Rows[myDGV.Rows.Count - 1].Cells["colSuppliers"]).Items.Clear;
                ((DataGridViewComboBoxCell)myDGV.Rows[myDGV.Rows.Count - 1].Cells["colSuppliers"]).Items.Add("Supplier A");
                ((DataGridViewComboBoxCell)myDGV.Rows[myDGV.Rows.Count - 1].Cells["colSuppliers"]).Items.Add("Supplier B");
                Hope it answers your question

                Comment

                • akal483
                  New Member
                  • Jul 2007
                  • 8

                  #9
                  Thank a lot RoninZa.
                  your guidance has solve my problem.

                  Regards
                  AL

                  Comment

                  Working...