S
Shmuel
Hi,
I have a tabbed panel that has a combobox.
Now, if I want to get the selected item I do something like this:
String fromlang = ((Language)cbList_FromLang.SelectedItem).abbrev;
Which works as expected. But if I browse to another tab and then
come back, the combobox has lost the selected item.
I still see the text in the combobox, but if I try same as code above
I get an error stating: 'Object reference not set to an instance of an
object'.
My question is that is this kind of behavior a bug or is it just a feature?
Any ideas how to bypass this annoyance?
I have come up with one (to manually set it again):
try {
fromlang = ((Language)cbList_FromLang.SelectedItem).abbrev;
}
catch(Exception e) {
if (cbList_FromLang.Text.Length > 0)
{
string text = cbList_FromLang.Text;
int i = 9999;
int count = 0;
foreach (Language l in cbList_FromLang.Items)
{
if (l.name == text)
{
i = count;
}
count++;
}
if (i != 9999)
{
cbList_FromLang.SelectedIndex = i;
try
{
fromlang =
((Language)cbList_FromLang.SelectedItem).abbrev;
}
catch (Exception ex) { }
}
}
}
But it is really cumbersome do do this for every element on every tab.
So if somebody has any better idea, I would be very glad to hear about it.
Thanks,
Shmuel
I have a tabbed panel that has a combobox.
Now, if I want to get the selected item I do something like this:
String fromlang = ((Language)cbList_FromLang.SelectedItem).abbrev;
Which works as expected. But if I browse to another tab and then
come back, the combobox has lost the selected item.
I still see the text in the combobox, but if I try same as code above
I get an error stating: 'Object reference not set to an instance of an
object'.
My question is that is this kind of behavior a bug or is it just a feature?
Any ideas how to bypass this annoyance?
I have come up with one (to manually set it again):
try {
fromlang = ((Language)cbList_FromLang.SelectedItem).abbrev;
}
catch(Exception e) {
if (cbList_FromLang.Text.Length > 0)
{
string text = cbList_FromLang.Text;
int i = 9999;
int count = 0;
foreach (Language l in cbList_FromLang.Items)
{
if (l.name == text)
{
i = count;
}
count++;
}
if (i != 9999)
{
cbList_FromLang.SelectedIndex = i;
try
{
fromlang =
((Language)cbList_FromLang.SelectedItem).abbrev;
}
catch (Exception ex) { }
}
}
}
But it is really cumbersome do do this for every element on every tab.
So if somebody has any better idea, I would be very glad to hear about it.
Thanks,
Shmuel