how to add a combo column to a data bound datagridview control

hi -- i'm using .net 3.5 and vs2008 and a windows forms control.  I want to contrain my users choices with a combo box on the datagridview control for a given column. the problem is that i'm populating from a dataset that is databound to the control. it appears that the 'automatic' poplulation of the grid from the dataset is with a textbox column.
it's not obvious how to override this.
Jim
jdcoburnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I am not sure that I completely understand your problem.  Are you saying that you want to filter the drop-down list for one column?
0
jdcoburnAuthor Commented:
no. I'm using the dataset designer to create the columns (as fields in the dataset). I open a xml file using ds.ReadXML(filename), create a datatable by referencing a table in the dataset and then bind the datagridview using  scriptDisplay_DGV.DataSource = dt. Because i'm using the dataset designer, i can only use text based columns. is there a way to use a combobox column using the dataset designer, or should i scrap the designer and manually create columns?
0
jdcoburnAuthor Commented:
I've played with this some more. i've eliminated the dataset designer by just creating a dataset, then binding the datagridview to a table in teh dataset. but my question remains the same -- how do i create a combo box column unless there's someting in the xml that tells the DGV to create a combo box columns for that field?
Jim
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Bob LearnedCommented:
You should be able to follow these steps to set a DataSource for the DataGridViewComboBoxColumn:

1) Set the DataSource for the column

2) Set the DisplayMember to a valid column name to set the display text.

3) Set the ValueMember to a valid column name to set the value returned when an option is selected.


Screenshot.png
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jdcoburnAuthor Commented:
I bound the whole control from the initial edit columns dialog box. this then generated the column, and i was able to modify the column type from that point. if i used your approach, i couldn't get it to recognize the data source.
thanks for the help.
0
Bob LearnedCommented:
Where and how is the data source defined?  Is it a typed DataSet that is defined on the form?
0
jdcoburnAuthor Commented:
hi -- this is a typed dataset. i suspect some of the confusion exists because i've partially implemented this in code and the rest using the dataset designer tool. I'll try and recap how i got to where i am:
i first built the dataset and datatable using the dataset design tool. i had also created a dataset using the control from the toolbox. the designer also created a binding source. so, the dataset designer tool created the schema necessary to import the xml file (which, from where i had started, had not been defined.) then i bound the datagridviedw to the datatable created as part of the dataset. this all worked fine, until i wanted to add a combobox column to the datagridview so that it constrained the choices for one of the columns.the designer itself will not allow a combobox column.

the code i run when i open the xml file is:

//get file name and display the file name using FileInfo
strFileName = openFileDialog.FileName;
shortName = openFileDialog.SafeFileName;

FileInfo fi = new FileInfo(strFileName);
ds.ReadXml(strFileName, XmlReadMode.InferTypedSchema);

dt = ds.Tables["ScriptTool_DT"];
scriptDisplay_DGV.DataSource = dt;

this.Text = "Script Tool Editor: " + shortName.Remove(shortName.Length - 5);

saveToolStripMenuItem.Enabled = true;
saveAsToolStripMenuItem.Enabled = true;
contentOpen = true;

Ultimately the way around this was to bind the datagridview on the first dialog screen (attached):
that generated the columns based on the xsd schema. then i went into the column editor and changed the type of column from text to combo. individual column binding didn't work.
Jim

first-image.jpg
0
Bob LearnedCommented:
1) You are using VS.NET 2010

2) There are mucho better ways to approach this problem, like using LINQ.

3) Doing the job in code gives you much more control over the process.
0
jdcoburnAuthor Commented:
1. yes, i upgraded part way through all ths thinking that vs2010 had a better solution. it didn't seem to matter.
2. I have no experience with LINQ but no reason to disagree. i don't normally deal with db apps.
3. I agree -- if i was going to start over, i would do it from scratch with code. but i thought as long as MS had this designer that might help documentation, i would try it.
0
Bob LearnedCommented:
If you want to use the designer, you need to use a specific sequence of events, and all the data sources need to be defined on the form, so that the DataGridView designer can find them.
0
jdcoburnAuthor Commented:
i realize that now. it appears that the designer presupposes a schema from an existing data source (eg a sql db.) I wanted to use the designer to create the schema for a data source -- an xml file. i have no experience writing a xml file from scratch, so i was hoping the schema would allow me to generate the file. it appears i started at the wrong place with the wrong tool . i eventually figured out how to create the file by using XMLspy.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.