473,564 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Selec tedIndex = cboServer.FindS tring(sServerNa me)

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

Throws this Error:

Run-time exception thrown : System.Argument Exception - Could not bind
to the new display member.
Parameter name: newDisplayMembe r

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 3095
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.FindS tring(Trim(sSer verName))

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.goo glegroups.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.Selec tedIndex = cboServer.FindS tring(sServerNa me)

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

Throws this Error:

Run-time exception thrown : System.Argument Exception - Could not bind
to the new display member.
Parameter name: newDisplayMembe r

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.Selec tedIndex = cboServer.FindS tring(sServerNa me)

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

? cboServer.FindS tring("ServerOn e")
Return 0

? cboServer.FindS tring("ServerTw o")
Returns 1

? cboServer.FindS tring("ServerTh ree")
Returns 2

When I set index I get the error
cboServer.Selec tedIndex = 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.Sele ctedIndex =
cboServer.FindS tring(sServerNa me)" 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.Selec tedIndex = 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.Selec tedIndex = cboServer.FindS tring(sServerNa me)

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

? cboServer.FindS tring("ServerOn e")
Return 0

? cboServer.FindS tring("ServerTw o")
Returns 1

? cboServer.FindS tring("ServerTh ree")
Returns 2

When I set index I get the error
cboServer.Selec tedIndex = 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.Sele ctedIndex =
cboServer.FindS tring(sServerNa me)" 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.Selec tedIndex = 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.FindS tring(sServerNa me)
cboServer.Selec tedIndex = 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.goo glegroups.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.Selec tedIndex = cboServer.FindS tring(sServerNa me)

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

? cboServer.FindS tring("ServerOn e")
Return 0

? cboServer.FindS tring("ServerTw o")
Returns 1

? cboServer.FindS tring("ServerTh ree")
Returns 2

When I set index I get the error
cboServer.Selec tedIndex = 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.Sele ctedIndex =
cboServer.FindS tring(sServerNa me)" 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.Selec tedIndex = 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
3606
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 value I am trying to set is present the items collection. I also have tried using .SelectedItem method and I get an object reference error. Any...
3
16192
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; comboBox.SelectedIndex = -1; ... }
2
4325
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 how to use this code? please help! http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20862953.html
7
20754
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. The control populates well, both the display values, and selected values. However, when i try to "set" the SelectedValue or SelectedIndex...
0
1717
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 twice: first call sets Index to 0, and only after second call selection is cleared. There is even bigger issue here. If my combo box is on a tabpage...
5
2139
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 drop down the combo box as the users typing. When the on leave event is fired the value in the selected
12
5060
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 names, and then I want to make sure nothing is selected. By default it appears that if you do nothing, the first item (0) is selected. However, I want...
30
4540
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 corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired...
5
6883
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
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.