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 when I initally
fill the ComboBox.
************************************************** *******
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Call LoadSystems()
Call Loademails(0)
End Sub
Private Sub LoadSystems()
Dim da As New SqlDataAdapter("COM_GET_SYSTEMS_SP", dbConn)
Dim ds As New DataSet
Dim dr As DataRow
da.Fill(ds, "Systems")
dr = ds.Tables("Systems").NewRow
dr(0) = 0
dr(1) = "All Emails"
ds.Tables("Systems").Rows.InsertAt(dr, 0)
SystemList.ValueMember = "id"
SystemList.DisplayMember = "name"
SystemList.DataSource = ds.Tables("Systems")
End Sub
Private Sub Loademails(ByVal systemID As Integer)
Dim da As New SqlDataAdapter("GetEmailMessages", dbConn)
da.SelectCommand.CommandType = CommandType.StoredProcedure
With da.SelectCommand.Parameters
If systemID <0 Then .Add("@SystemID", SqlDbType.Int).Value =
systemID
End With
Try
If Not ds.Tables("Emails") Is Nothing Then
ds.Tables.Remove("Emails")
da.Fill(ds, "Emails")
EmailDataGrid.DataSource = ds.Tables("Emails")
' EmailDataGrid.AllowSorting = False
EmailDataGrid.ReadOnly = True
Catch ex As Exception
Dim temp As String = ex.Message
End Try
End Sub
Private Sub SystemList_SelectedIndexChanged(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
SystemList.SelectedIndexChanged
Loademails(sender.SelectedValue)
End Sub
************************************************** ********************
Thanks,
Tom 2 2930
Either;
Use RemoveHandler and AddHandler to turn the remove the event handler for
SelectIndexChanged while you do your thing in the load event then add the
event handler back in before you exit the load event.
Use a form scoped variable to detect when the load event is being processed.
--
Dennis in Houston
"tshad" wrote:
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 when I initally
fill the ComboBox.
************************************************** *******
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Call LoadSystems()
Call Loademails(0)
End Sub
Private Sub LoadSystems()
Dim da As New SqlDataAdapter("COM_GET_SYSTEMS_SP", dbConn)
Dim ds As New DataSet
Dim dr As DataRow
da.Fill(ds, "Systems")
dr = ds.Tables("Systems").NewRow
dr(0) = 0
dr(1) = "All Emails"
ds.Tables("Systems").Rows.InsertAt(dr, 0)
SystemList.ValueMember = "id"
SystemList.DisplayMember = "name"
SystemList.DataSource = ds.Tables("Systems")
End Sub
Private Sub Loademails(ByVal systemID As Integer)
Dim da As New SqlDataAdapter("GetEmailMessages", dbConn)
da.SelectCommand.CommandType = CommandType.StoredProcedure
With da.SelectCommand.Parameters
If systemID <0 Then .Add("@SystemID", SqlDbType.Int).Value =
systemID
End With
Try
If Not ds.Tables("Emails") Is Nothing Then
ds.Tables.Remove("Emails")
da.Fill(ds, "Emails")
EmailDataGrid.DataSource = ds.Tables("Emails")
' EmailDataGrid.AllowSorting = False
EmailDataGrid.ReadOnly = True
Catch ex As Exception
Dim temp As String = ex.Message
End Try
End Sub
Private Sub SystemList_SelectedIndexChanged(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
SystemList.SelectedIndexChanged
Loademails(sender.SelectedValue)
End Sub
************************************************** ********************
Thanks,
Tom
"tshad" <tf*@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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 when I
initally fill the ComboBox.
************************************************** *******
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Call LoadSystems()
Call Loademails(0)
End Sub
Private Sub LoadSystems()
Dim da As New SqlDataAdapter("COM_GET_SYSTEMS_SP", dbConn)
Dim ds As New DataSet
Dim dr As DataRow
da.Fill(ds, "Systems")
dr = ds.Tables("Systems").NewRow
dr(0) = 0
dr(1) = "All Emails"
ds.Tables("Systems").Rows.InsertAt(dr, 0)
SystemList.ValueMember = "id"
SystemList.DisplayMember = "name"
SystemList.DataSource = ds.Tables("Systems")
End Sub
Private Sub Loademails(ByVal systemID As Integer)
Dim da As New SqlDataAdapter("GetEmailMessages", dbConn)
da.SelectCommand.CommandType = CommandType.StoredProcedure
With da.SelectCommand.Parameters
If systemID <0 Then .Add("@SystemID", SqlDbType.Int).Value =
systemID
End With
Try
If Not ds.Tables("Emails") Is Nothing Then
ds.Tables.Remove("Emails")
da.Fill(ds, "Emails")
EmailDataGrid.DataSource = ds.Tables("Emails")
' EmailDataGrid.AllowSorting = False
EmailDataGrid.ReadOnly = True
Catch ex As Exception
Dim temp As String = ex.Message
End Try
End Sub
Private Sub SystemList_SelectedIndexChanged(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
SystemList.SelectedIndexChanged
Loademails(sender.SelectedValue)
End Sub
************************************************** ********************
Thanks,
Tom
Maybe I am an old dude with this, but in VB6 I always used a "loading"
variable to stop events firing until the load finished. In VB.Net 2005, I
still use the same construct, eg
_loading = true 'module level var
With MyCombo
.Datasource = MyObject.GetData()
.DisplayValue = "Description"
.ValueMember = "Pointer"
.SelectedIndex = -1
_loading = false
If .Items.Count 0 Then
.SelectedIndex = 0 'or whatever you want it to be
End if
End With
and in the cbo.SelectedIndexChanged event add code something like:
If Not _loading AndAlso (cbo.SelectedIndex -1) Then
'do whatever
End If
As I say, old dudes code, but it works real fine for me. Maybe someone can
suggest a better way to do this?
Harry This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ceci |
last post by:
I need help!! I'm using the selectedindexchanged event of a combobox to fill
another combobox according to the selected value of the first one, but the
combobox_selectedindexchanged happens twice...
|
by: sandman |
last post by:
I've got a combo box that has an event handler set for
SelectedIndexChanged event. The problem is that it's
firing at startup when I load data from the Form_OnLoad
event. I tried setting a flag...
|
by: Keith |
last post by:
Hello - this started out as a minor annoyance - and now is
starting to bother me more and more - I'm hoping someone
can help me.
I would like to have a combobox display - NOT initially be
blank...
|
by: sparkle |
last post by:
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...
|
by: Tand35006 |
last post by:
Hi, I hope some one can help with this. I have a basic webform with 2
DropDownLists and a single DataGrid. What I am trying to do is populate the
first DDList from a dataset on Form_Load. I then...
|
by: blue_nirvana |
last post by:
I use a AddHandler statement in the load event of a form to assoicate a
routine with a combobox. When I populate the form, I select the approiate
value from the combobox by using...
|
by: toufik |
last post by:
Hi,
I've 2 comboboxes with a methode selectedIndexchanged defined in each.
In the sub combobox1_selectedindexchanged I fill the combobox2, in this case
the event selectedindexchanged of the...
|
by: tbrown |
last post by:
I have a combobox with items like this: {one,two,three}. The selected
index is 0, so "one" appears in the combobox text. When the user drops
down the list, and selects "two", for example, I...
|
by: lakepeir |
last post by:
Hello,
I have combobox with a selectedindexchanged method that seems to be
called when starting the application, launching the form with the
combobox and making a change in the drop down box of...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
|
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...
|
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...
|
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: 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: 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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |