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

Testing ListBox.SelectedValue after index changed event

The first time I run my code the list box sends a selected index
changed event even though at this point there has been no activity
with the mouse. The value returned from SelectedValue according to the
debugger is System.Data.DataRowView.

How can I either stop this initial selected index changed event from
happening automatically or alternatively what can I check for so that
I can avoid executing further code if the selected value is not an
int? The problem with this is that I have to cast the returned object
before I can check it so cannot really check for a specific type.

Thanks,
Rich.

lbxTraining.DataSource = empTraining;
lbxTraining.DisplayMember = "display";
lbxTraining.ValueMember = "value";

private void lbxTraining_SelectedIndexChanged(object sender, EventArgs
e)
{
int i = int.Parse(lbxTraining.SelectedValue.ToString());
empTraining = dbEmployeeCom.getEmployeeTraining(i, employee);
}

Apr 25 '07 #1
1 2480
Mel
One way is adding a variable during startup or change of datasource

bool startup = true;
lbxTraining.DataSource = empTraining;
lbxTraining.DisplayMember = "display";
lbxTraining.ValueMember = "value";
startup = false;
>
private void lbxTraining_SelectedIndexChanged(object sender, EventArgs
e)
{
if (!startup)
{
int i = int.Parse(lbxTraining.SelectedValue.ToString());
empTraining = dbEmployeeCom.getEmployeeTraining(i, employee);
}
>


"RichGK" <Ri****@hotmail.co.ukwrote in message
news:11**********************@n15g2000prd.googlegr oups.com...
The first time I run my code the list box sends a selected index
changed event even though at this point there has been no activity
with the mouse. The value returned from SelectedValue according to the
debugger is System.Data.DataRowView.

How can I either stop this initial selected index changed event from
happening automatically or alternatively what can I check for so that
I can avoid executing further code if the selected value is not an
int? The problem with this is that I have to cast the returned object
before I can check it so cannot really check for a specific type.

Thanks,
Rich.

lbxTraining.DataSource = empTraining;
lbxTraining.DisplayMember = "display";
lbxTraining.ValueMember = "value";

private void lbxTraining_SelectedIndexChanged(object sender, EventArgs
e)
{
int i = int.Parse(lbxTraining.SelectedValue.ToString());
empTraining = dbEmployeeCom.getEmployeeTraining(i, employee);
}

Apr 25 '07 #2

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

Similar topics

3
by: amber | last post by:
Hello, I'm having trouble findingwhich event I need to use with a listbox. When a user selects a new item in the listbox, I want to trigger an event BEFORE the new item is actually selected. ...
6
by: jez123456 | last post by:
Hi I have a windows form with 3 ListBoxes. m_listBoxUsers – this displays all users from a database. m_listBoxRoles – this displays available roles that can be assigned to users....
10
by: yop | last post by:
All When I try to get the text from my listbox I am get an error which is listed below. Any ideas? Thanks Object reference not set to an instance of an object.
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
0
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem...
1
by: RichGK | last post by:
The first time I run my code the list box sends a selected index changed event even though at this point there has been no activity with the mouse. The value returned from SelectedValue according...
2
by: =?Utf-8?B?U3RlcGhlbiBSaXRjaGll?= | last post by:
Hi NET1.1 / Winforms I have a listbox that I am binding to a table via the DataSource property. However I want to be able to programmatically select values in this listbox so I am using the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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?
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...
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,...

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.