473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

ComboBox - Setting the SelectedIndex - Throwing an error

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.

Nov 21 '05 #1
5 3084
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

<jo********@usa.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.

Nov 21 '05 #2
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

Nov 21 '05 #3
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

Nov 21 '05 #4
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
<jo********@usa.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 21 '05 #5
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
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fred | last post by:
Hi, I am having a problem setting a combobox value in code on form load using comboBox.SelectedValue method. The code below when debugging show the combobox equal to an undefined value. The...
3
by: ScottO | last post by:
I would like the user to have to select something in a System.Windows.Forms.ComboBox. private void MyForm_Load(object sender, System.EventArgs e) { ... comboBox.DataSource = data;...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
0
by: Alex K. | last post by:
Hi all I noticed that if I link a combobox to data table (setting DataSource property), then it is very hard to clear selection by setting SelectedIndex = -1. I have to set SelectedIndex = -1...
5
by: ross kerr | last post by:
Hi All, I am extending the combobox to create a control that selects an item based on the text the user is typing into the text area of the control. I have an issue that occurs only when i...
12
by: Steve Dyte | last post by:
Hi, I've narrowed down a problem I've been having filling a combobox with the results of a query stored in a datatable. I'm setting the ValueMember and DisplayMember to the relevant column...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
5
by: Rotsey | last post by:
Hi, I have a combobox that when I set the SelectedIndex to -1 it sets to 0. The combobox Items property says there is 20 items in it. Anyone know why this could be please? rotsey
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.