By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,710 Members | 1,613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,710 IT Pros & Developers. It's quick & easy.

Testing ListBox.SelectedValue after index changed event

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.