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

C# windows Assign a value to DataGridViewComboBox cell based on another row

Expert 5K+
P: 7,872
I feel like this question has been asked before, but I couldn't find it.
I think I am missing something obvious.

Basically I am going to have a DataGridView with two columns. One textbox, one combobox.
The textbox column is going to be coming from a database (actually I could manually create it if i had to). It makes about 20 rows, each with a unique value for the textbox column.
The available choices for the combobox row are coming from a list (I apply it as a datasource currently, it might be better if I manually add the items?)

So for each entry, you can pick a value from a combox, pretty simple, that part works.

Now what I want is, based on some criteria, that a certain value in the combobox field be "selected" by start, instead of an empty box.

I am roughly going to take a particular string, and if its a choice in the combobox, select it. If it is NOT a choice, select the first item in the combobox.

I cannot seem to set the combobox value. With a regular combobox, there is a .Contains on the items (items is always empty when using a datasource) and then is has a .SelectedItem property. The Selected whatever properties aren't on thse DataGridViewComboBox cells.

I have tried just setting the .Value property of the cell, which correctly triggers the DataError event if it's not a choice, but then the value cannot be re-set based on that?

EDIT: I attached a picture of desired output. I can correctly set the values (using the Items.Contains()) now, but it only actually sets the value if I have "looked" at the DataGridView first (its on another tab)
Attached Images
File Type: jpg desiredlayout.JPG (14.5 KB, 397 views)
Oct 30 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 7,872
What I ended up doing was putting it all on the main tab...and hoping it doesn't cause anymore issues
Oct 31 '08 #2

Post your reply

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