PC Review


Reply
Thread Tools Rate Thread

Combobox SelectedItem

 
 
Shmuel
Guest
Posts: n/a
 
      22nd Sep 2008
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
 
Reply With Quote
 
 
 
 
G Himangi
Guest
Posts: n/a
 
      24th Sep 2008
Try setting the DropDownList property to DropDownList

---------
- G Himangi, LogicNP Software http://www.ssware.com
Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
Browsing Functionality (.Net & ActiveX Editions).
EZNamespaceExtensions: Develop namespace extensions rapidly in .Net and
MFC/ATL/C++
EZShellExtensions: Develop all shell extensions,explorer bars and BHOs
rapidly in .Net & MFC/ATL/C++
---------


"Shmuel" <(E-Mail Removed)> wrote in message
news:gb8q61$pli$(E-Mail Removed)...
> 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



 
Reply With Quote
 
Jeff Johnson
Guest
Posts: n/a
 
      25th Sep 2008
"G Himangi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> Try setting the DropDownList property to DropDownList


DropDownStyle property.


 
Reply With Quote
 
Shmuel
Guest
Posts: n/a
 
      26th Sep 2008
It has the same problem. After visiting another tab and coming back
there is no selected item, it is blank. I want them to be unchanged
even if I decide to visit another tab

The DropDown style doesn't loose the text, but the DropDownList does.



G Himangi wrote:
> Try setting the DropDownList property to DropDownList
>
> ---------
> - G Himangi, LogicNP Software http://www.ssware.com
> Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
> Browsing Functionality (.Net & ActiveX Editions).
> EZNamespaceExtensions: Develop namespace extensions rapidly in .Net and
> MFC/ATL/C++
> EZShellExtensions: Develop all shell extensions,explorer bars and BHOs
> rapidly in .Net & MFC/ATL/C++
> ---------
>
>
> "Shmuel" <(E-Mail Removed)> wrote in message
> news:gb8q61$pli$(E-Mail Removed)...
>> 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

>
>

 
Reply With Quote
 
Jeff Johnson
Guest
Posts: n/a
 
      26th Sep 2008
"Shmuel" <(E-Mail Removed)> wrote in message
news:gb8q61$pli$(E-Mail Removed)...

> But if I browse to another tab and then
> come back, the combobox has lost the selected item.


That is NOT normal behavior. I would feel safe betting that there is code
somewhere in your project that is resetting the selections on these combo
boxes when you change tabs. That's where you need to look. Step through,
step through.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using a combobox.selecteditem Peted Microsoft C# .NET 1 22nd Jan 2009 07:13 AM
Combobox SelectedItem Robert Microsoft Dot NET Framework Forms 1 11th Jan 2008 07:35 PM
combobox.SelectedItem woes? =?Utf-8?B?SlA=?= Microsoft Dot NET 1 27th Oct 2006 02:59 PM
How to set ComboBox's SelectedItem with an object Sérgio Pinheiro Microsoft Dot NET Compact Framework 2 4th May 2004 05:05 PM
Setting the SelectedItem of a ComboBox using an ID Lee Ottaway Microsoft Dot NET Framework Forms 3 5th Nov 2003 04:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:50 AM.