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

combobox fill causing SelectedIndexChanged 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 SelectedIndexChanged 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.Vehicle
VehicleInfo = ClassVehicleID.GetAllVehicles
With cboSearchCountyVehicle
' .DataSource = VehicleInfo
.DisplayMember = "VehicleID"
.ValueMember = "VehicleID"
.SelectedIndex = -1
End With
Private Sub cboSearchCountyVehicle_SelectedIndexChanged(ByVal
sender As Object, ByVal e As System.EventArgs) Handles
cboSearchCountyVehicle.SelectedIndexChanged

LoadPermitInfofromCountyVehicle()

End Sub

Nov 21 '05 #1
7 8768
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 SelectedIndexChanged 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.Vehicle
VehicleInfo = ClassVehicleID.GetAllVehicles
With cboSearchCountyVehicle
' .DataSource = VehicleInfo
.DisplayMember = "VehicleID"
.ValueMember = "VehicleID"
.SelectedIndex = -1
End With
Private Sub cboSearchCountyVehicle_SelectedIndexChanged(ByVal
sender As Object, ByVal e As System.EventArgs) Handles
cboSearchCountyVehicle.SelectedIndexChanged

LoadPermitInfofromCountyVehicle()

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 SelectedIndexChanged 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
selectedindexchanged event. So, let us see the code that runs when you call
LoadPermitInfofromCountyVehicle(). 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 SelectedIndexChanged 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. SelectedIndexChanged 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 selectedindexchanged to do something,
for instance, now I'm filling in a datagrid. Put your breakpoint on
the combobox fill and selectedIndexChanged 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 selectedindexchanged 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. SelectedIndexChanged 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 selectedindexchanged to do something,
for instance, now I'm filling in a datagrid. Put your breakpoint on
the combobox fill and selectedIndexChanged 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 cboCountyVehicle_SelectedIndexChanged_1(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
cboCountyVehicle.SelectedIndexChanged

if cboCountyVehicle.SelectedIndex >= 1 Then
BindAutosGridbyVehicleID()
end if

End Sub
' BIND AUTOS GRID code

Sub BindAutosGridbyVehicleID()
Dim ClassVehicleID As New ParkingPermits.BizLogic.Vehicle
Dim VehicleInfo As ParkingPermits.info.VehicleInfo()
VehicleInfo =
ClassVehicleID.GetVehicleByVehicleID(cboCountyVehi cle.SelectedValue)
'If VehicleInfo.Length = 0 Then
' MessageBox.Show("Vehicle not found for " +
cboCountyVehicle.Text.Trim + ".", App.MessageCaption,
MessageBoxButtons.OK, MessageBoxIcon.Information)
'Else
_ArrayBinding = VehicleInfo
grdAutos.DataSource = _ArrayBinding

Dim grid As DataGridTableStyle = New DataGridTableStyle
grid.MappingName = _ArrayBinding.GetType().Name

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

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

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

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

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

grid.GridColumnStyles.AddRange(New DataGridColumnStyle()
{ColumnMake, ColumnModel, _
ColumnLicense, ColumnYear, ColumnColor})
grdAutos.TableStyles.Add(grid)
grdAutos.TableStyles.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 cboCountyVehicle_SelectedIndexChanged_1(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
cboCountyVehicle.SelectedIndexChanged

if cboCountyVehicle.SelectedIndex >= 1 Then
BindAutosGridbyVehicleID()
end if

End Sub
' BIND AUTOS GRID code

Sub BindAutosGridbyVehicleID()
Dim ClassVehicleID As New ParkingPermits.BizLogic.Vehicle
Dim VehicleInfo As ParkingPermits.info.VehicleInfo()
VehicleInfo =
ClassVehicleID.GetVehicleByVehicleID(cboCountyVehi cle.SelectedValue)
'If VehicleInfo.Length = 0 Then
' MessageBox.Show("Vehicle not found for " +
cboCountyVehicle.Text.Trim + ".", App.MessageCaption,
MessageBoxButtons.OK, MessageBoxIcon.Information)
'Else
_ArrayBinding = VehicleInfo
grdAutos.DataSource = _ArrayBinding

Dim grid As DataGridTableStyle = New DataGridTableStyle
grid.MappingName = _ArrayBinding.GetType().Name

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

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

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

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

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

grid.GridColumnStyles.AddRange(New DataGridColumnStyle()
{ColumnMake, ColumnModel, _
ColumnLicense, ColumnYear, ColumnColor})
grdAutos.TableStyles.Add(grid)
grdAutos.TableStyles.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
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
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...
4
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...
2
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...
5
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...
3
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...
2
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...
4
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
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.