How to fill a combobox column in a datagridview programatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Motawee
    New Member
    • Mar 2010
    • 3

    How to fill a combobox column in a datagridview programatically

    i am making a windows form application that contains a datagridview that is filled with employees names

    the program is for the attendance absence holidays of employees in the company

    so i created a combobox column in the datagridview beside the holiday checkbox so when the dataentry check the holiday checkbox he can choose what type of holiday is this to subtract it from the employee holiday counter

    i need to fill this combobox column with values returned from a database, i returned those values within a dataset but i need to know how to bind this dataset to the combobox

    in normal combobox i used
    Code:
    combobox1.datasource = DS.table[0];
    combobox1.displaymember = "Employees_name"; //for example
    so how i can bind this DataSet to the combobox column in the datagrid, is there a way like what i did with normal comboboxes .. and if i want to set the value of this combobox column manually depending on something else how could i add a value manually?

    in normal comboboxes i write
    Code:
    combobox1.text = "Casual";
    so how to do that too in the combobox column within the datagridview

    thx a lot for ur time reading this .. really appreciate it :)
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Database tutorial Part 1
    Database tutorial Part 2

    Comment

    • Motawee
      New Member
      • Mar 2010
      • 3

      #3
      Thx for the reply tlhintoq but thats not what i need at all :)

      i asked for a way to fill a combobox in a datagridview i know how to deal with the SQL server programatically

      so please if anyone can help .. just need to fill a combobox in a datagridview AFTER retrieving the data from the data base in a DataSet .. i need to show the data in this DataSet in the combobox in the datagridview .. then i need to know how to set this combobox to a certain value entered manually..

      anyways thx for ur time :)

      Comment

      • Motawee
        New Member
        • Mar 2010
        • 3

        #4
        I found the answer at last .. if any one faces the same problem simply do the following

        Code:
        DataGridViewComboBoxCell ComboColumn = (DataGridViewComboBoxCell)(dataGridView4.Rows[i].Cells[0]);
                        
        ComboColumn.DataSource = DataSserH.Tables[0];
        ComboColumn.DisplayMember = "Employee_Names";
        so u just have to define a new DataGridViewCom boBoxCell and bind it to the datagridview combobox column but dont forget to make the cast or it will not work ..

        thx for anyone who took the time to try and help :)

        Comment

        Working...