473,382 Members | 1,717 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,382 software developers and data experts.

Combobox exception - xpost/C# forum

Hi... Synposis...

Throws exception:
"Specified argument was out of the range of valid values."
Read on for the juicy tidbits.

MySimpleClassCol mscc=new MySimpleClassCol();

private void InitCombo()
{
// Doing this so bind op doesn't fire event
m_combo.SelectedIndexChanged -= new System.EventHandler...
mscc.Clear();
XmlNodeList nl=m_xml.DocumentElement.SelectNodes("/a/b/c/d");
foreach(XmlNode n in nl)
{
// Grab a bunch of strings from the node innerxml
MySimpleClass sc=new MySimpleClass(s1, s2, s3, s4);
mscc.Add(sc);
}
m_combo.DataSource=null;
m_combo.DataSource=mscc;
m_combo.DisplayMember="ComboName";
m_combo.SelectedIndex=-1;
m_combo.SelectedIndex=-1;
m-combo.SelectedIndexChanged += new System.EventHandler...
try
{
if(m_combo.Items.Count>0)
m_combo.SelectedIndex=0;
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
}

InitCombo is called on Form load. It is also called whenever a change
is made to the underlying XML document.

Scenario 1:
1. Add a <d> node to the XML document
2. Save XML document to disk
3. InitCombo()
4. m_combo.SelectedIndex=m_combo.FindStringExact(newV alue);

This works.

Scenario 2:
1. Remove an inner <d> XML node - NOT the last one added
2. Save XML document to disk
3. InitCombo()
4. Leave m_combo.SelectedIndex=0;

This works.

Scenario 3:
1. Remove the last XML node added - always last child of parent node <c>
2. Save XML document to disk
3. InitCombo()

THIS BLOWS UP on:

try
{
if(m_combo.Items.Count>0) // which it is...
m_combo.SelectedIndex=0; // Throws exception
}

The exception thrown is:
"Specified argument was out of the range of valid values.
Parameter name: Index was out of range.
Must be non-negative and less than the size of the collection."

Nice... except that .Count is non-zero, 0 is non-negative, and less than
the size of the collection. And it ONLY happens when I remove the last child
in the XML... which corresponds to the last item in the list.

<a>
<b>
<c>
<d name="OKToDelete">
</d>
<d name="OKToDelete">
</d>
<d name="OKToDelete">
</d>
<d name="BLOWS_UP_ONDelete">
</d>
</c>
</b>
</a>

I have fiddled with the event handlers. I've tried NOT rebinding and just
repopulating the data set. I have all but waved a dead chicken over
the keyboard.

Could anyone throw me a bone here?

Thanks,
M.


Nov 22 '05 #1
0 1102

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

Similar topics

1
by: Michael Conroy | last post by:
Hi... Synposis... Throws exception: "Specified argument was out of the range of valid values." Read on for the juicy tidbits. MySimpleClassCol mscc=new MySimpleClassCol(); private void...
6
by: Omar | last post by:
When I try to databind my comboBox (specifically field "emplcode") to a filled dataset , the contents of the comboBox displays a bunch of "System.Data.DataRowView". I assume the amount of times...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
0
by: Doug | last post by:
This is a repost of an item that I still cannot resolve. I have 3 combo boxes. The first leads to the second to the third. When I have selected a value in the second box, the third box shows...
20
by: MadCrazyNewbie | last post by:
Hey group, I keep getting the following error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll Additional information: There is no row at...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
1
by: polocar | last post by:
Ciao a tutti, leggendo qua e lą per il forum ho scoperto che non sono l'unico ad avere questo problema. Se si inserisce un controllo ComboBox in un form di C#, non č possibile impostare la sua...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
8
by: kimtherkelsen | last post by:
Hi, I do this: this.comboBox.DataSource = myDataSet.Tables.Select("location_key = " + selectedLocationKey); this.comboBox.DisplayMember = "text"; this.comboBox.ValueMember =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.