473,581 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

combobox fill causing SelectedIndexCh anged without selecting

Hi Everybody,

I'm filling a combobox from a class, which works fine on it's own.

But when I insert code to fill in other controls something in the
combobox fill is causing the SelectedIndexCh anged event to happen
when the form (hence combobox) loads, not when I select something
from the combobox.

Do I have something in the wrong order? I've read that that sometimes
makes a difference...

Thanks for any suggestions,
Here's my code:

Dim ClassVehicleID As New ParkingPermits. BizLogic.Vehicl e
VehicleInfo = ClassVehicleID. GetAllVehicles
With cboSearchCounty Vehicle
' .DataSource = VehicleInfo
.DisplayMember = "VehicleID"
.ValueMember = "VehicleID"
.SelectedIndex = -1
End With
Private Sub cboSearchCounty Vehicle_Selecte dIndexChanged(B yVal
sender As Object, ByVal e As System.EventArg s) Handles
cboSearchCounty Vehicle.Selecte dIndexChanged

LoadPermitInfof romCountyVehicl e()

End Sub

Nov 21 '05 #1
7 8785
Hi,

Try setting selectedindex = -1 twice - there is a known bug in the framework
on this.

HTH,

Bernie Yaeger

"sparkle" <hr****@hra.co. santa-cruz.ca-dot-us.no-spam.invalid> wrote in
message news:41******** **@Usenet.com.. .
Hi Everybody,

I'm filling a combobox from a class, which works fine on it's own.

But when I insert code to fill in other controls something in the
combobox fill is causing the SelectedIndexCh anged event to happen
when the form (hence combobox) loads, not when I select something
from the combobox.

Do I have something in the wrong order? I've read that that sometimes
makes a difference...

Thanks for any suggestions,
Here's my code:

Dim ClassVehicleID As New ParkingPermits. BizLogic.Vehicl e
VehicleInfo = ClassVehicleID. GetAllVehicles
With cboSearchCounty Vehicle
' .DataSource = VehicleInfo
.DisplayMember = "VehicleID"
.ValueMember = "VehicleID"
.SelectedIndex = -1
End With
Private Sub cboSearchCounty Vehicle_Selecte dIndexChanged(B yVal
sender As Object, ByVal e As System.EventArg s) Handles
cboSearchCounty Vehicle.Selecte dIndexChanged

LoadPermitInfof romCountyVehicl e()

End Sub

Nov 21 '05 #2
Thanks Bernie,

I should have mentioned that I had already tried that earlier with no
change in results. I don't think it's the same bug. The one I saw was
that SelectedIndexCh anged wasn't fired.

In my case it fires for no reason.

Still looking for a solution because I really want to use a combobox
for this!

Nov 21 '05 #3
Hi,

Well, when you set selectedindex = -1 you are probably firing the
selectedindexch anged event. So, let us see the code that runs when you call
LoadPermitInfof romCountyVehicl e(). Something in there must be firing the
event again.

Bernie

"sparkle" <hr****@hra.co. santa-cruz.ca-dot-us.no-spam.invalid> wrote in
message news:41******** @Usenet.com...
Thanks Bernie,

I should have mentioned that I had already tried that earlier with no
change in results. I don't think it's the same bug. The one I saw was
that SelectedIndexCh anged wasn't fired.

In my case it fires for no reason.

Still looking for a solution because I really want to use a combobox
for this!

Nov 21 '05 #4
Thanks for sticking with me, Bernie.

Here's what I found. SelectedIndexCh anged is fired when a form loads
and when the selected index of the combobox is set to -1. So
potentially twice before you even select an item in the combobox. And
that it happens when you bind to a datasource.

Only found a couple of suggestions in articles, neither of which I
have gotten to work:

http://www.winnetmag.com/MobileWirel...ess_41825.html

http://www.knowdotnet.com/articles/protectevents.html

To try this, you just need a combobox that fills from a datasource on
form_load, then set the combo's selectedindexch anged to do something,
for instance, now I'm filling in a datagrid. Put your breakpoint on
the combobox fill and selectedIndexCh anged event and you'll see.

For now, I'm doing something hokey; hiding the datagrid until after I
have selected something. I'd like a better workaround if you find
something out!

Nov 21 '05 #5
Hi Sparkle,

Well, the knowledgebase article really doesn't answer your need. I'm glad
you've found a workaround, but I'd still like to see the code that is called
inside the selectedindexch anged event.

Bernie

"sparkle" <hr****@hra.co. santa-cruz.ca-dot-us.no-spam.invalid> wrote in
message news:41******** @Usenet.com...
Thanks for sticking with me, Bernie.

Here's what I found. SelectedIndexCh anged is fired when a form loads
and when the selected index of the combobox is set to -1. So
potentially twice before you even select an item in the combobox. And
that it happens when you bind to a datasource.

Only found a couple of suggestions in articles, neither of which I
have gotten to work:

http://www.winnetmag.com/MobileWirel...ess_41825.html
http://www.knowdotnet.com/articles/protectevents.html

To try this, you just need a combobox that fills from a datasource on
form_load, then set the combo's selectedindexch anged to do something,
for instance, now I'm filling in a datagrid. Put your breakpoint on
the combobox fill and selectedIndexCh anged event and you'll see.

For now, I'm doing something hokey; hiding the datagrid until after I
have selected something. I'd like a better workaround if you find
something out!

Nov 21 '05 #6
Ok, here you go. This workaround isn't great, so if we can figure out
a better way, I'll be glad:

Have you tried a test yourself? I didn't really see it having to do
with the code binding the AutosGrid, but fresh eyes will be
appreciated...

'SELECTED INDEX CHANGED code
Private Sub cboCountyVehicl e_SelectedIndex Changed_1(ByVal sender
As System.Object, ByVal e As System.EventArg s) Handles
cboCountyVehicl e.SelectedIndex Changed

if cboCountyVehicl e.SelectedIndex >= 1 Then
BindAutosGridby VehicleID()
end if

End Sub
' BIND AUTOS GRID code

Sub BindAutosGridby VehicleID()
Dim ClassVehicleID As New ParkingPermits. BizLogic.Vehicl e
Dim VehicleInfo As ParkingPermits. info.VehicleInf o()
VehicleInfo =
ClassVehicleID. GetVehicleByVeh icleID(cboCount yVehicle.Select edValue)
'If VehicleInfo.Len gth = 0 Then
' MessageBox.Show ("Vehicle not found for " +
cboCountyVehicl e.Text.Trim + ".", App.MessageCapt ion,
MessageBoxButto ns.OK, MessageBoxIcon. Information)
'Else
_ArrayBinding = VehicleInfo
grdAutos.DataSo urce = _ArrayBinding

Dim grid As DataGridTableSt yle = New DataGridTableSt yle
grid.MappingNam e = _ArrayBinding.G etType().Name

Dim ColumnMake As New DataGridTextBox Column
With ColumnMake
.MappingName = "Make"
.HeaderText = "Make"
.Width = 70
End With

Dim ColumnModel As New DataGridTextBox Column
With ColumnModel
.MappingName = "model"
.HeaderText = "Model"
.Width = 90
End With

Dim ColumnLicense As New DataGridTextBox Column
With ColumnLicense
.MappingName = "license"
.HeaderText = "License"
.Width = 65
End With

Dim ColumnYear As New DataGridTextBox Column
With ColumnYear
.MappingName = "year"
.HeaderText = "Year"
.Width = 65
End With

Dim ColumnColor As New DataGridTextBox Column
With ColumnColor
.MappingName = "Color"
.HeaderText = "Color"
.Width = 60
End With

grid.GridColumn Styles.AddRange (New DataGridColumnS tyle()
{ColumnMake, ColumnModel, _
ColumnLicense, ColumnYear, ColumnColor})
grdAutos.TableS tyles.Add(grid)
grdAutos.TableS tyles.Clear()
End Sub

#End Region 'autos grid

Nov 21 '05 #7
Hi Sparkle,

I'm afraid I see nothing; sorry. I will keep looking, though.

Bernie

"sparkle" <hr****@hra.co. santa-cruz.ca-dot-us.no-spam.invalid> wrote in
message news:41******** **@Usenet.com.. .
Ok, here you go. This workaround isn't great, so if we can figure out
a better way, I'll be glad:

Have you tried a test yourself? I didn't really see it having to do
with the code binding the AutosGrid, but fresh eyes will be
appreciated...

'SELECTED INDEX CHANGED code
Private Sub cboCountyVehicl e_SelectedIndex Changed_1(ByVal sender
As System.Object, ByVal e As System.EventArg s) Handles
cboCountyVehicl e.SelectedIndex Changed

if cboCountyVehicl e.SelectedIndex >= 1 Then
BindAutosGridby VehicleID()
end if

End Sub
' BIND AUTOS GRID code

Sub BindAutosGridby VehicleID()
Dim ClassVehicleID As New ParkingPermits. BizLogic.Vehicl e
Dim VehicleInfo As ParkingPermits. info.VehicleInf o()
VehicleInfo =
ClassVehicleID. GetVehicleByVeh icleID(cboCount yVehicle.Select edValue)
'If VehicleInfo.Len gth = 0 Then
' MessageBox.Show ("Vehicle not found for " +
cboCountyVehicl e.Text.Trim + ".", App.MessageCapt ion,
MessageBoxButto ns.OK, MessageBoxIcon. Information)
'Else
_ArrayBinding = VehicleInfo
grdAutos.DataSo urce = _ArrayBinding

Dim grid As DataGridTableSt yle = New DataGridTableSt yle
grid.MappingNam e = _ArrayBinding.G etType().Name

Dim ColumnMake As New DataGridTextBox Column
With ColumnMake
.MappingName = "Make"
.HeaderText = "Make"
.Width = 70
End With

Dim ColumnModel As New DataGridTextBox Column
With ColumnModel
.MappingName = "model"
.HeaderText = "Model"
.Width = 90
End With

Dim ColumnLicense As New DataGridTextBox Column
With ColumnLicense
.MappingName = "license"
.HeaderText = "License"
.Width = 65
End With

Dim ColumnYear As New DataGridTextBox Column
With ColumnYear
.MappingName = "year"
.HeaderText = "Year"
.Width = 65
End With

Dim ColumnColor As New DataGridTextBox Column
With ColumnColor
.MappingName = "Color"
.HeaderText = "Color"
.Width = 60
End With

grid.GridColumn Styles.AddRange (New DataGridColumnS tyle()
{ColumnMake, ColumnModel, _
ColumnLicense, ColumnYear, ColumnColor})
grdAutos.TableS tyles.Add(grid)
grdAutos.TableS tyles.Clear()
End Sub

#End Region 'autos grid

Nov 21 '05 #8

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

Similar topics

1
4960
by: Tamir Gal | last post by:
Hi, I'm using the CheckedListBox control, and I'm wondering if there is a way to let the user check an item in the list without also selecting it... Any ideas? Thanks in advance, Tamir.
0
1264
by: tshad | last post by:
MSN has a toolbar that has a Form Fill function that will try to fill form fields on forms when they come up. The problem is that it causes problems with some forms and functions. I found this out this weekend. If you have your address set up in your Form Fill function, any form that has these fields (name, address, city, phone etc) will...
4
9533
by: Anson | last post by:
Dear all, This questions seems simple to most of you, but I just couldn't figure it out. I have a combobox. I want to capture the value (or index) of the combo box just **before** the user click on the box and change the value. I know I can use a flag to remember this value. But is there any better way to do it?
2
12053
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
The auto-generated line of code to fill a DataGridView once it is placed on the designer surface in VS2005 is typically: this.xyzTableAdapter.Fill(this.myDataSet.MyMember); But if the query takes a long time to run, this freezes the UI (in a Windows Forms application). What is the best practice for filling a DataGridView without freezing...
5
11635
by: Matt B | last post by:
I know this is a bit of nonstandard behavior, but I would like the Enter key to move focus through a group of radiobuttons without selecting them. The user would then have to use Space or actually click to select one of the radiobuttons to select. The default behavior of Focus() seems to also select the radiobutton, but I can't seem to...
3
1853
by: phanimadhav | last post by:
hi this is sudheer, i am new one of this ASP.NET .i have one problem,i am using gridview control i know how to place the dropdownlistbox in gridview control.in my gridveiw control have contain totally 4 columns. The first 3 columns are bounded fields and the 4 th one is dropdownlistcontrol.the first 3 boundedfields are filled by using one table...
2
2942
by: tshad | last post by:
In my VS 2003 Windows Forms page, when I initially fill my ComboBox (SystemList), it goes to the SelectedIndexChanged event which calls the Loademails() function. I then call it again in the Form1Load function. How do I get it not to call it in the SelectedIndexChanged from the Form1Load function? Normally, I want it to call it but not...
4
1337
by: selvaonline | last post by:
hi frnds, I had created an windows application project in that i like to use a drop-down combobox for both entering a text and also for retrive. what i need to do.
0
1231
by: kumardharanik | last post by:
i need to fill the datatable(datagridview) without using the database.. Here is my code.. But i cant able to fill the datatable [CODE} Public Sub CreateDatatable() dtable = New DataTable("purchasedetails_table") Dim column As DataColumn column = New DataColumn()
0
7854
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7878
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6533
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5349
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3806
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1394
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1118
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.