Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is weird and I cannot find an answer to this. I have a form with several controls on it, of which there are three Comboboxes. There is also a datagrid where selecting a row in the datagrid provides editable details in the form controls below. The funny thing is that one of the comboboxes gets populated whilst the other two don't. I've checked it programatically and the item being selected by the set value is correct and contains all the right information but the text area of the box is blank.

Change the selection on the combobox manually, then restart the whole selection on the grid again and presto things work!

BTW, by setting value I mean along the lines of

MyCombo.SelectedValue = ((MyItem)MyDatagridView.DataboundItem).MyComboValue;

(Of course, its a bit more complicated and complete than the snippet above :) )

The comboboxes are databound and the data is correct.

Another thing I might add is that the SelectedIndex remains 0 when it should be something else. (That basically summarizes my whole predicament)

Any ideas?
Posted
Updated 19-Aug-10 11:19am
v2

1 solution

Perhaps try setting both SelectedValue and SelectedText? Or maybe you'd have better luck setting SelectedIndex.
 
Share this answer
 
Comments
AspDotNetDev 19-Aug-10 17:42pm    
If you only know the value and not the index, loop through all the values until you find the correct one, remember that index, then set SelectedIndex to that index.
Mustafa Ismail Mustafa 19-Aug-10 19:07pm    
Oh man, talk about taking a few steps back! :)

I just tried setting the index, out of frustration ya dig, and still no go. I have found that until I have manually altered the selection on the front end, nothing will happen. Once I have changed it manually, things work right which is not making any sense to me.

I think I will be setting the text as well, but that has to be a temp solution.
AspDotNetDev 19-Aug-10 19:24pm    
Perhaps you need to databind before you set the index. And perhaps the reason it seems to be working the second time, is because you are databinding then (and the subsequent index setting works). If you are using AJAX (e.g., update panels), that can cause some havoc as well.
AspDotNetDev 19-Aug-10 21:56pm    
Oh, you're not using ASP.Net... duh :-P

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900