combobox in datagridview

In VS2005 winforms C#
I am looking for an example of combobox column in a gridview.
How to set the datasource of the combobox.
How to show the existing value and how to update it with the combo.
Thankyou
Anat
ANAT2403Asked:
Who is Participating?
 
Priest04Commented:
It all depends what will be the datasource of the combobox column. You can add items manually (assuming DataGridViewComboBoxColumn's name is Column2)

Column2.Items.Add("1st");
Items.Add("2nd");
Column2.Items.Add("3rd");

or in one line

Column2.Items.AddRange(New String() {"1st", "2nd", "3rd"})

or if you want to bind it to datatable

Column2.DisplayMember = "name";
Column2.ValueMember = "name";
Column2.DataSource = dt;

You can read this article on MSDN about DataGridViewComboBoxColumn

http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx

Goran
0
 
ANAT2403Author Commented:
Hi,
I don't understand how I the example in the link. I took the version for framework 2..0
but usually the Main in in a different file program.cs so if the main is on the same file how do i  run it?
Thankyou
Anat
0
 
ANAT2403Author Commented:
I meant how I run this application.
Anat
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Priest04Commented:
There are several ways you can run this. The easiest one is to create new class:

Create new project, delete Program.cs and Form1, and add New Class, delete the existing code in it and paste the code from article.

Note that you need to have SQL server running in order to run the example.

Goran
0
 
ANAT2403Author Commented:
Hi,
O.K. it worked for me. thank you.
just one small question:
Do you have any idea why when you press the arrow in the combo you have to press it twice untill it opens the combo. It work like this also in Microsoft example.
Thankyou
Anat
0
 
Priest04Commented:
It is the standard behavior of DataGridViewComboBoxColumn. The first click is giving it the focus while the 2nd one is for opening list.

Goran
0
 
Priest04Commented:
You are welcome.

Goran
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.