By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How to fill a combobox column in a datagridview programatically

P: 3
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
Expand|Select|Wrap|Line Numbers
  1. combobox1.datasource = DS.table[0];
  2. combobox1.displaymember = "Employees_name"; //for example
  3.  
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
Expand|Select|Wrap|Line Numbers
  1. combobox1.text = "Casual";
  2.  
so how to do that too in the combobox column within the datagridview

thx a lot for ur time reading this .. really appreciate it :)
Mar 31 '10 #1

✓ answered by Motawee

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

Expand|Select|Wrap|Line Numbers
  1. DataGridViewComboBoxCell ComboColumn = (DataGridViewComboBoxCell)(dataGridView4.Rows[i].Cells[0]);
  2.  
  3. ComboColumn.DataSource = DataSserH.Tables[0];
  4. ComboColumn.DisplayMember = "Employee_Names";
  5.  
  6.  
so u just have to define a new DataGridViewComboBoxCell 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 :)

Share this Question
Share on Google+
3 Replies


P: 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 :)
Mar 31 '10 #3

P: 3
I found the answer at last .. if any one faces the same problem simply do the following

Expand|Select|Wrap|Line Numbers
  1. DataGridViewComboBoxCell ComboColumn = (DataGridViewComboBoxCell)(dataGridView4.Rows[i].Cells[0]);
  2.  
  3. ComboColumn.DataSource = DataSserH.Tables[0];
  4. ComboColumn.DisplayMember = "Employee_Names";
  5.  
  6.  
so u just have to define a new DataGridViewComboBoxCell 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 :)
Apr 1 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.