[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

combobox in datagridview

Posted on 2007-07-30
7
Medium Priority
?
1,038 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:ANAT2403
  • 4
  • 3
7 Comments
 
LVL 18

Accepted Solution

by:
Priest04 earned 2000 total points
ID: 19595957
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
 

Author Comment

by:ANAT2403
ID: 19597600
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
 

Author Comment

by:ANAT2403
ID: 19597699
I meant how I run this application.
Anat
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 18

Expert Comment

by:Priest04
ID: 19598718
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
 

Author Comment

by:ANAT2403
ID: 19599454
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
 
LVL 18

Expert Comment

by:Priest04
ID: 19599573
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
 
LVL 18

Expert Comment

by:Priest04
ID: 19599576
You are welcome.

Goran
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question