To reproduce, run the code.
Observed:
System.ArgumentOutOfRangeException was unhandled
Message="InvalidArgument=Value of '0' is not valid for
'SelectedIndex'.\r\nParameter name: SelectedIndex"
t2.c1 contains legal value.
Why this error occurs ?
How to fix ?
Andrus.
using System.Windows.Forms;
using System.Data;
using System;
class testForm : Form {
testForm() {
DataTable t = new DataTable();
t.Columns.Add("displaymember");
t.Columns.Add("valuemember");
t.Rows.Add("lower", "l");
ComboBox comboBox1 = new ComboBox();
comboBox1.DisplayMember = "displaymember";
comboBox1.ValueMember = "valuemember";
comboBox1.DataSource = t;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
DataTable t2 = new DataTable();
t2.Columns.Add("c1");
t2.Rows.Add("l");
comboBox1.DataBindings.Add("SelectedValue", t2, "c1");
Controls.AddRange(new Control[] { comboBox1 });
}
[STAThread]
static void Main() {
Application.Run(new testForm());
}
} 5 16446
It isn't legal if it's a string.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net
"Andrus" <ko********@hot.eewrote in message
news:eM**************@TK2MSFTNGP05.phx.gbl...
To reproduce, run the code.
Observed:
System.ArgumentOutOfRangeException was unhandled
Message="InvalidArgument=Value of '0' is not valid for
'SelectedIndex'.\r\nParameter name: SelectedIndex"
t2.c1 contains legal value.
Why this error occurs ?
How to fix ?
Andrus.
using System.Windows.Forms;
using System.Data;
using System;
class testForm : Form {
testForm() {
DataTable t = new DataTable();
t.Columns.Add("displaymember");
t.Columns.Add("valuemember");
t.Rows.Add("lower", "l");
ComboBox comboBox1 = new ComboBox();
comboBox1.DisplayMember = "displaymember";
comboBox1.ValueMember = "valuemember";
comboBox1.DataSource = t;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
DataTable t2 = new DataTable();
t2.Columns.Add("c1");
t2.Rows.Add("l");
comboBox1.DataBindings.Add("SelectedValue", t2, "c1");
Controls.AddRange(new Control[] { comboBox1 });
}
[STAThread]
static void Main() {
Application.Run(new testForm());
}
}
Kevin,
thank you.
The code does not set SelectedIndex as all.
Why .NET tries to set SelectedIndex to invalid value ?
Andrus.
It isn't legal if it's a string.
>> Observed: System.ArgumentOutOfRangeException was unhandled Message="InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.\r\nParameter name: SelectedIndex"
t2.c1 contains legal value. Why this error occurs ? How to fix ?
Andrus.
using System.Windows.Forms; using System.Data; using System; class testForm : Form {
testForm() { DataTable t = new DataTable(); t.Columns.Add("displaymember"); t.Columns.Add("valuemember"); t.Rows.Add("lower", "l");
ComboBox comboBox1 = new ComboBox(); comboBox1.DisplayMember = "displaymember"; comboBox1.ValueMember = "valuemember"; comboBox1.DataSource = t; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
DataTable t2 = new DataTable(); t2.Columns.Add("c1"); t2.Rows.Add("l"); comboBox1.DataBindings.Add("SelectedValue", t2, "c1"); Controls.AddRange(new Control[] { comboBox1 }); }
[STAThread] static void Main() { Application.Run(new testForm()); } }
Andrus wrote:
To reproduce, run the code.
Observed:
System.ArgumentOutOfRangeException was unhandled
Message="InvalidArgument=Value of '0' is not valid for
'SelectedIndex'.\r\nParameter name: SelectedIndex"
t2.c1 contains legal value.
Why this error occurs ?
How to fix ?
Andrus.
using System.Windows.Forms;
using System.Data;
using System;
class testForm : Form {
testForm() {
DataTable t = new DataTable();
t.Columns.Add("displaymember");
t.Columns.Add("valuemember");
t.Rows.Add("lower", "l");
ComboBox comboBox1 = new ComboBox();
comboBox1.DisplayMember = "displaymember";
comboBox1.ValueMember = "valuemember";
comboBox1.DataSource = t;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
DataTable t2 = new DataTable();
t2.Columns.Add("c1");
t2.Rows.Add("l");
comboBox1.DataBindings.Add("SelectedValue", t2, "c1");
Controls.AddRange(new Control[] { comboBox1 });
}
[STAThread]
static void Main() {
Application.Run(new testForm());
}
}
You can't select a specific item from a combobox that doesn't contain
any items at all.
You haven't databound the combobox, so it doesn't contain any items.
--
Göran Andersson
_____ http://www.guffa.com
Andrus wrote:
Kevin,
thank you.
The code does not set SelectedIndex as all.
Why .NET tries to set SelectedIndex to invalid value ?
Andrus.
You are setting the SelectedValue property. That will basically look for
the value among the items, and set the SelectedIndex property for the
matching item.
--
Göran Andersson
_____ http://www.guffa.com
Andrus wrote:
To reproduce, run the code.
Observed:
System.ArgumentOutOfRangeException was unhandled
Message="InvalidArgument=Value of '0' is not valid for
'SelectedIndex'.\r\nParameter name: SelectedIndex"
t2.c1 contains legal value.
Why this error occurs ?
How to fix ?
Andrus.
using System.Windows.Forms;
using System.Data;
using System;
class testForm : Form {
testForm() {
DataTable t = new DataTable();
t.Columns.Add("displaymember");
t.Columns.Add("valuemember");
t.Rows.Add("lower", "l");
ComboBox comboBox1 = new ComboBox();
comboBox1.DisplayMember = "displaymember";
comboBox1.ValueMember = "valuemember";
comboBox1.DataSource = t;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
DataTable t2 = new DataTable();
t2.Columns.Add("c1");
t2.Rows.Add("l");
comboBox1.DataBindings.Add("SelectedValue", t2, "c1");
Controls.AddRange(new Control[] { comboBox1 });
}
[STAThread]
static void Main() {
Application.Run(new testForm());
}
}
Hi,
This is *totally* a guess, because I haven't tried your code, but try moving
this line:
comboBox1.DataSource = t;
So it immediately follows this line:
ComboBox comboBox1 = new ComboBox();
--
Tom Spink
University of Edinburgh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cwizard |
last post by:
I'm calling on a function from within this form, and there are values set
but every time it gets called I get slammed with a run time error...
document.frmKitAmount.txtTotalKitValue is null or not...
|
by: ???????J |
last post by:
Javascript may inquire the push down menu value, can I inquire the
description?
The following example, the variable($answer) can be get the menu1's
value.
For example, if I select first data,...
|
by: niyong |
last post by:
--
Hop@Ni
|
by: hodari |
last post by:
The compiler complains that zero is not acceptable value for selectedIndex.
What I am doing is loading up the combo box with the data from a dataset and
then setting the SelectedIndex value to zero...
|
by: Benedict Teoh |
last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
|
by: JSantora |
last post by:
Essentially, InsertAT is broken!
For the past couple of hours, I've been getting this "Parameter name:
'-2147483550' is not a valid value for 'index'." error.
Apparently, its caused by having...
|
by: Jim Carlock |
last post by:
Does a SELECT element (listbox) need to be inside
a FORM element?
The code I'm playing with:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
|
by: Harris |
last post by:
Dear all,
I have the following codes:
======
public enum Enum_Value
{
Value0 = 0,
Value1 = 10,
|
by: kang jia |
last post by:
hi
currently i am editing signup page, when user enter deupicated NRIC and click signup, they will go to do_signuppage and read the error message and then after 5 seconds, they will be redirected...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
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...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |