In my VS 2003 Windows Forms page, when I initially fill my ComboBox
(SystemList), it goes to the SelectedIndexCh anged 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 SelectedIndexCh anged from the
Form1Load function? Normally, I want it to call it but not when I initally
fill the ComboBox.
*************** *************** *************** ************
Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Call LoadSystems()
Call Loademails(0)
End Sub
Private Sub LoadSystems()
Dim da As New SqlDataAdapter( "COM_GET_SYSTEM S_SP", dbConn)
Dim ds As New DataSet
Dim dr As DataRow
da.Fill(ds, "Systems")
dr = ds.Tables("Syst ems").NewRow
dr(0) = 0
dr(1) = "All Emails"
ds.Tables("Syst ems").Rows.Inse rtAt(dr, 0)
SystemList.Valu eMember = "id"
SystemList.Disp layMember = "name"
SystemList.Data Source = ds.Tables("Syst ems")
End Sub
Private Sub Loademails(ByVa l systemID As Integer)
Dim da As New SqlDataAdapter( "GetEmailMessag es", dbConn)
da.SelectComman d.CommandType = CommandType.Sto redProcedure
With da.SelectComman d.Parameters
If systemID <0 Then .Add("@SystemID ", SqlDbType.Int). Value =
systemID
End With
Try
If Not ds.Tables("Emai ls") Is Nothing Then
ds.Tables.Remov e("Emails")
da.Fill(ds, "Emails")
EmailDataGrid.D ataSource = ds.Tables("Emai ls")
' EmailDataGrid.A llowSorting = False
EmailDataGrid.R eadOnly = True
Catch ex As Exception
Dim temp As String = ex.Message
End Try
End Sub
Private Sub SystemList_Sele ctedIndexChange d(ByVal sender As
System.Object, _
ByVal e As System.EventArg s) Handles
SystemList.Sele ctedIndexChange d
Loademails(send er.SelectedValu e)
End Sub
*************** *************** *************** *************** **********
Thanks,
Tom 2 2951
Either;
Use RemoveHandler and AddHandler to turn the remove the event handler for
SelectIndexChan ged 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 SelectedIndexCh anged 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 SelectedIndexCh anged from the
Form1Load function? Normally, I want it to call it but not when I initally
fill the ComboBox.
*************** *************** *************** ************
Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Call LoadSystems()
Call Loademails(0)
End Sub
Private Sub LoadSystems()
Dim da As New SqlDataAdapter( "COM_GET_SYSTEM S_SP", dbConn)
Dim ds As New DataSet
Dim dr As DataRow
da.Fill(ds, "Systems")
dr = ds.Tables("Syst ems").NewRow
dr(0) = 0
dr(1) = "All Emails"
ds.Tables("Syst ems").Rows.Inse rtAt(dr, 0)
SystemList.Valu eMember = "id"
SystemList.Disp layMember = "name"
SystemList.Data Source = ds.Tables("Syst ems")
End Sub
Private Sub Loademails(ByVa l systemID As Integer)
Dim da As New SqlDataAdapter( "GetEmailMessag es", dbConn)
da.SelectComman d.CommandType = CommandType.Sto redProcedure
With da.SelectComman d.Parameters
If systemID <0 Then .Add("@SystemID ", SqlDbType.Int). Value =
systemID
End With
Try
If Not ds.Tables("Emai ls") Is Nothing Then
ds.Tables.Remov e("Emails")
da.Fill(ds, "Emails")
EmailDataGrid.D ataSource = ds.Tables("Emai ls")
' EmailDataGrid.A llowSorting = False
EmailDataGrid.R eadOnly = True
Catch ex As Exception
Dim temp As String = ex.Message
End Try
End Sub
Private Sub SystemList_Sele ctedIndexChange d(ByVal sender As
System.Object, _
ByVal e As System.EventArg s) Handles
SystemList.Sele ctedIndexChange d
Loademails(send er.SelectedValu e)
End Sub
*************** *************** *************** *************** **********
Thanks,
Tom
"tshad" <tf*@dslextreme .comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
In my VS 2003 Windows Forms page, when I initially fill my ComboBox
(SystemList), it goes to the SelectedIndexCh anged 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 SelectedIndexCh anged from the
Form1Load function? Normally, I want it to call it but not when I
initally fill the ComboBox.
*************** *************** *************** ************
Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Call LoadSystems()
Call Loademails(0)
End Sub
Private Sub LoadSystems()
Dim da As New SqlDataAdapter( "COM_GET_SYSTEM S_SP", dbConn)
Dim ds As New DataSet
Dim dr As DataRow
da.Fill(ds, "Systems")
dr = ds.Tables("Syst ems").NewRow
dr(0) = 0
dr(1) = "All Emails"
ds.Tables("Syst ems").Rows.Inse rtAt(dr, 0)
SystemList.Valu eMember = "id"
SystemList.Disp layMember = "name"
SystemList.Data Source = ds.Tables("Syst ems")
End Sub
Private Sub Loademails(ByVa l systemID As Integer)
Dim da As New SqlDataAdapter( "GetEmailMessag es", dbConn)
da.SelectComman d.CommandType = CommandType.Sto redProcedure
With da.SelectComman d.Parameters
If systemID <0 Then .Add("@SystemID ", SqlDbType.Int). Value =
systemID
End With
Try
If Not ds.Tables("Emai ls") Is Nothing Then
ds.Tables.Remov e("Emails")
da.Fill(ds, "Emails")
EmailDataGrid.D ataSource = ds.Tables("Emai ls")
' EmailDataGrid.A llowSorting = False
EmailDataGrid.R eadOnly = True
Catch ex As Exception
Dim temp As String = ex.Message
End Try
End Sub
Private Sub SystemList_Sele ctedIndexChange d(ByVal sender As
System.Object, _
ByVal e As System.EventArg s) Handles
SystemList.Sele ctedIndexChange d
Loademails(send er.SelectedValu e)
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.GetDat a()
.DisplayValue = "Descriptio n"
.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.SelectedInd exChanged event add code something like:
If Not _loading AndAlso (cbo.SelectedIn dex -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 so the same routine of searching
data occurs twice!!! So my application takes twice the time it should take. I
debug that part of my application, and when it reaches the end sub of that
subrutine the first time, the event takes place again, so the...
|
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 at startup and turning it
off at the end of the OnLoad function but the
SelectedIndexChange event gets called after OnLoad
finishes, so my flag is off. How can I get around this?
Is there another event that I can use to turn the flag
off? Or...
|
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 - but contain a value. However the value is just
for user reference - not really one of the combobox
choices. For example intially the combobox should equal
the word Select - and the item values can be
say 'one', 'two', and 'three'.
|
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 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
|
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 want to use this 1st DDList
to populate the 2nd DDList via the SelectedIndexChange Event.
So far so good. all works up to this point.
The next thing I'm trying to do is to use the 2nd DDList value in a queery
to populate the Datagrid also...
| |
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 combobox.selectedvalue = value. The weird
thing is sometimes this causes the assoicated routine to be called and
sometimes it does not. The combobox below it that is completely identical
except for the name works every time. After the form is displayed, you can...
|
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 combobox2 is raised.
This is working in some machines but in some other machines this doesn't
happen, the event selectedindexchanged isn't raised, and the sub
combobox2_selectedindexchanged isn't executed.
The both machines are the same with...
|
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 modify the Items
collection to be {two,one,three} and now want "two" to appear in the
combobox text. However, the combobox text is now blank. the is apparently
somehow the result of having changed the combobox.Items collection.
If, trying to fix...
|
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 the combobox. Can
anyone tell me why the method is called so often? I would only like
the method executed when a user makes a change in the drop down box.
Am I using the incorrect method. Thanks.
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |