473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
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 :)

3 43642
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
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

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

Similar topics

4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
3
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my...
2
by: David Jackson | last post by:
Hello, I have an unbound DataGridView of which one of the columns is a ComboBox colum containing category data, plus an additional option called <newSo when the ComboBox is dropped down it looks...
1
by: Ananthu | last post by:
Hi I have combobox column in datagridview.I have loaded a particular database table column value into it from my mysql database. The combobox in all the rows is filled with my database value...
0
by: priyamtheone | last post by:
There's an editable datagridview populated from a table say tblItems. Among the columns of the datagridview there's a combobox column named 'Category'. This column is populated by the respective...
0
by: priyamtheone | last post by:
I have a dgv that's bound to a table tblQuoteItems. One of the columns of the dgv is ItemID which is a combobox column. Its value is obtained from ItemID field of tblQuoteItems. Before binding...
0
by: Moorthi chinna | last post by:
how to reload combobox in datagridview based on combobox selection in datagridview?
1
by: Hardy123 | last post by:
Hi, I am having a combobox column in a datagridview named "dgcProfessor" which contains the list of professors names. i am filling that column with a datatable Now that datatable have more than...
0
by: visweswaran2830 | last post by:
Hi, I am having datagridview in that I have datagridview combobox column and noraml textfield. I want to know that how can I load selected value in that combox box when I am loading all entered...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.