PC Review


Reply
Thread Tools Rate Thread

ComboBox - Setting the SelectedIndex - Throwing an error

 
 
john.halet@usa.net
Guest
Posts: n/a
 
      8th Aug 2005
This line of code had been working with out issue, now its throwing
errors.

In my case I have three items in the ComboBox. If I try to change the
selected index it throw the error.

Earler in the code I check to see if the combobox has any items, if so
then I set it to 0 with out issue.

Then a bit later in the code I try to set it to the last server used.

cboServer.SelectedIndex = cboServer.FindString(sServerName)

I try in in the command window and get the same results.
cboServer.SelectedIndex = 1

Throws this Error:

Run-time exception thrown : System.ArgumentException - Could not bind
to the new display member.
Parameter name: newDisplayMember

I've seen several postings about this error message but none have
anyting to do with the SelectedIndex.

Does anyone have any ideas as to what may be happening?
Any thoughts, ideas would be appreciated.

 
Reply With Quote
 
 
 
 
Phil
Guest
Posts: n/a
 
      8th Aug 2005
Hi John,

I'm not sure that I can answer your question without a little more
understanding of what is going on. One thing that immediately puzzles me is
your comment about setting the selectedindex directly from the IDE. Unless
you have somehow cleared your itemlist or you only have one item (zero based
index) I don't see the problem with this statement.

Have you tried cboServer.FindString(Trim(sServerName))

Have you tried returning some properties of the cbo immediately before
setting the SelectedIndex?

Rgds,

Phil

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This line of code had been working with out issue, now its throwing
> errors.
>
> In my case I have three items in the ComboBox. If I try to change the
> selected index it throw the error.
>
> Earler in the code I check to see if the combobox has any items, if so
> then I set it to 0 with out issue.
>
> Then a bit later in the code I try to set it to the last server used.
>
> cboServer.SelectedIndex = cboServer.FindString(sServerName)
>
> I try in in the command window and get the same results.
> cboServer.SelectedIndex = 1
>
> Throws this Error:
>
> Run-time exception thrown : System.ArgumentException - Could not bind
> to the new display member.
> Parameter name: newDisplayMember
>
> I've seen several postings about this error message but none have
> anyting to do with the SelectedIndex.
>
> Does anyone have any ideas as to what may be happening?
> Any thoughts, ideas would be appreciated.
>



 
Reply With Quote
 
john.halet@usa.net
Guest
Posts: n/a
 
      8th Aug 2005
Hi Phil

I have tried returning some properties from the combo box.
I put a break point in the code (on the line of code below) and printed
out a few items such as items.count etc... in the command window.
cboServer.SelectedIndex = cboServer.FindString(sServerName)

I have tried finding the server names in the combo box.

? cboServer.FindString("ServerOne")
Return 0

? cboServer.FindString("ServerTwo")
Returns 1

? cboServer.FindString("ServerThree")
Returns 2

When I set index I get the error
cboServer.SelectedIndex = 1

The combo box is loaded with the informaiton I want.

When I try to set the index of the combobox I get that error.

If I comment out the "cboServer.SelectedIndex =
cboServer.FindString(sServerName)" the applicaiton runs and you are
able to use the combo box.

Its very strange... Yesterday I was using the application and it
worked fine. I came back a few minutes later to use that application
and found that was throwing erros when it loaded?
I checked out the source code and begain testing and found that it was
complaining about setting the Selected Index?

This should work...

I tried setting the index to something that was not valid for the list.
cboServer.SelectedIndex = 23

I got the expected message complaining about an invalid index value.

Not sure where to look for answers.


John

 
Reply With Quote
 
john.halet@usa.net
Guest
Posts: n/a
 
      8th Aug 2005
Hi Phil

I have tried returning some properties from the combo box.
I put a break point in the code (on the line of code below) and printed
out a few items such as items.count etc... in the command window.
cboServer.SelectedIndex = cboServer.FindString(sServerName)

I have tried finding the server names in the combo box.

? cboServer.FindString("ServerOne")
Return 0

? cboServer.FindString("ServerTwo")
Returns 1

? cboServer.FindString("ServerThree")
Returns 2

When I set index I get the error
cboServer.SelectedIndex = 1

The combo box is loaded with the informaiton I want.

When I try to set the index of the combobox I get that error.

If I comment out the "cboServer.SelectedIndex =
cboServer.FindString(sServerName)" the applicaiton runs and you are
able to use the combo box.

Its very strange... Yesterday I was using the application and it
worked fine. I came back a few minutes later to use that application
and found that was throwing erros when it loaded?
I checked out the source code and begain testing and found that it was
complaining about setting the Selected Index?

This should work...

I tried setting the index to something that was not valid for the list.
cboServer.SelectedIndex = 23

I got the expected message complaining about an invalid index value.

Not sure where to look for answers.


John

 
Reply With Quote
 
Phil
Guest
Posts: n/a
 
      8th Aug 2005
John,

I know it 'shouldn't' make any difference and it is the same thing but an
additional step, (you may have tried this!).

Dim intRet as integer
intRet = cboServer.FindString(sServerName)
cboServer.SelectedIndex = intRet

Is it the same result?

Like you, the problem isn't jumping out at me.........and especially as IT
WAS working (Grrrrrr). Good luck ;-)

Phil


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Phil
>
> I have tried returning some properties from the combo box.
> I put a break point in the code (on the line of code below) and printed
> out a few items such as items.count etc... in the command window.
> cboServer.SelectedIndex = cboServer.FindString(sServerName)
>
> I have tried finding the server names in the combo box.
>
> ? cboServer.FindString("ServerOne")
> Return 0
>
> ? cboServer.FindString("ServerTwo")
> Returns 1
>
> ? cboServer.FindString("ServerThree")
> Returns 2
>
> When I set index I get the error
> cboServer.SelectedIndex = 1
>
> The combo box is loaded with the informaiton I want.
>
> When I try to set the index of the combobox I get that error.
>
> If I comment out the "cboServer.SelectedIndex =
> cboServer.FindString(sServerName)" the applicaiton runs and you are
> able to use the combo box.
>
> Its very strange... Yesterday I was using the application and it
> worked fine. I came back a few minutes later to use that application
> and found that was throwing erros when it loaded?
> I checked out the source code and begain testing and found that it was
> complaining about setting the Selected Index?
>
> This should work...
>
> I tried setting the index to something that was not valid for the list.
> cboServer.SelectedIndex = 23
>
> I got the expected message complaining about an invalid index value.
>
> Not sure where to look for answers.
>
>
> John
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      9th Aug 2005
John,

Where are you setting this and is there more code around.

By instance setting the selected index inside the selected index change
event, gives mostly a lot of trouble if there is not a protection that the
set itself throws an selected index change event.

I hope this helps,

Cor


 
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
ComboBox Setting both DataSource and SelectedIndex samueltilden@gmail.com Microsoft C# .NET 2 29th Feb 2008 10:01 PM
Setting combobox selectedindex Rotsey Microsoft C# .NET 5 1st Jul 2007 03:56 PM
combobox.SelectedIndex = -1 does not empty combobox =?Utf-8?B?d2VzYmlyZA==?= Microsoft Dot NET Framework Forms 1 24th Mar 2006 02:56 PM
ComboBox.SelectedIndex = -1 Ralf Ziller Microsoft Dot NET Compact Framework 2 18th Jan 2005 05:40 PM
ComboBox SelectedIndex is set to 0 Albert Microsoft Dot NET Framework Forms 2 18th Sep 2003 09:02 AM


Features
 

Advertising
 

Newsgroups
 


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