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

setting DataSource fires 'SlectedIndexChanged' event too!

TF
hi,
i am using a ListBox control on a windows form using VB.Net. when i
set the DataSource property of the control to an ArrayList it fires
following events in this order:
SelectedIndexChanged
SelectedIndexChanged
DataSourceChanged
SelectedIndexChanged

is there any way to check in SelectedIndexChanged event handler that
if event is fired while setting DataSource property or user has
actually changed the item? SelectedIndex property doesn't work 'cause
it is already set to '0'.

BTW, why SelectedIndexChanged is fired 3-times?

Any help...
Thanks
TF
Nov 22 '05 #1
4 2301
I have experienced this same problem in the past and have
resolved the issue by using a no-so-elegant but workable
solution using a module level boolean variable.

For example, declare a variable in your form as such...

Private mboolSettingDataSource As Boolean = False

Then prior to setting the DataSource property set the
variable to True then after setting the DataSource
property set the variable back to False.

Then at the begining of the SelectedIndexChanged event
place a code snipet like...

If mboolSettingDataSource Then
Exit Sub
End If

FWIW: I believe the reason the SelectedIndexChanged event
fires multiple times is because internally the DataSource
property actually changes the SelectedIndex porperty
(probably once for each element in the array).

I hope this helps!
-----Original Message-----
hi,
i am using a ListBox control on a windows form using VB.Net. when iset the DataSource property of the control to an ArrayList it firesfollowing events in this order:
SelectedIndexChanged
SelectedIndexChanged
DataSourceChanged
SelectedIndexChanged

is there any way to check in SelectedIndexChanged event handler thatif event is fired while setting DataSource property or user hasactually changed the item? SelectedIndex property doesn't work 'causeit is already set to '0'.

BTW, why SelectedIndexChanged is fired 3-times?

Any help...
Thanks
TF
.

Nov 22 '05 #2
I have experienced this same problem in the past and have
resolved the issue by using a no-so-elegant but workable
solution using a module level boolean variable.

For example, declare a variable in your form as such...

Private mboolSettingDataSource As Boolean = False

Then prior to setting the DataSource property set the
variable to True then after setting the DataSource
property set the variable back to False.

Then at the begining of the SelectedIndexChanged event
place a code snipet like...

If mboolSettingDataSource Then
Exit Sub
End If

FWIW: I believe the reason the SelectedIndexChanged event
fires multiple times is because internally the DataSource
property actually changes the SelectedIndex porperty
(probably once for each element in the array).

I hope this helps!
-----Original Message-----
hi,
i am using a ListBox control on a windows form using VB.Net. when iset the DataSource property of the control to an ArrayList it firesfollowing events in this order:
SelectedIndexChanged
SelectedIndexChanged
DataSourceChanged
SelectedIndexChanged

is there any way to check in SelectedIndexChanged event handler thatif event is fired while setting DataSource property or user hasactually changed the item? SelectedIndex property doesn't work 'causeit is already set to '0'.

BTW, why SelectedIndexChanged is fired 3-times?

Any help...
Thanks
TF
.

Nov 22 '05 #3
TF
yes, i did same sort of thing but i was wondering if i am missing something.

Thanks for reply
Nov 22 '05 #4
TF
yes, i did same sort of thing but i was wondering if i am missing something.

Thanks for reply
Nov 22 '05 #5

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

Similar topics

2
by: TF | last post by:
hi, i am using a ListBox control on a windows form using VB.Net. when i set the DataSource property of the control to an ArrayList it fires following events in this order: SelectedIndexChanged...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
19
by: Heidi Hundåla | last post by:
Hi ! I have a Wep App in C#. Page_Unload fires after Page_Load, and it seems totally unreasonable when you want to use this event when you _leave_ the page. In my project we wanted to use...
3
by: Hartmut Schroth | last post by:
Hi, I need a solution for the following problem: In the item template of a datalist control I have already a button control with the commandname set to "select" to perform some specific...
8
by: Nevyn Twyll | last post by:
I have a multi-level datalist setup: DataList1 DataList2 MyGrid I have columns explicitly defined for the grid in the html. Sometimes, On the initial Load() of the Page, I want to add extra...
5
by: Russell Smallwood | last post by:
Hello all, Why can't I wire up an event during the "Raise PostBackEvent" stage of a postback? Just in case this is the wrong question, the situation: deep in the bowls of some code-behind...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
1
by: David Veeneman | last post by:
I am writing a control that relies on its host to validate the contents of one of its fields. The control fires a custom 'FooNeedsValidating' event and passes the field's data with the event. The...
3
by: doctorle | last post by:
I'm surprised that the Current event of forms always fires twice (Access XP). I have quite a lot of processing done in the current event, how to make the code run just once? Thanks
1
by: progressdll | last post by:
I'm trying to change the behaviour of setting the DataSource property of combobox. Here is the behaviour I now see. Setting the DataSource property of combobox to an ArrayList will visual...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.