Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Problems Firing an Event Handler

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shookim@gmail.com - 31 Jan 2007 22:42 GMT
I am trying to populate a combobox and then fire an indexchanged event
handler.  My combobox populates fine, the problem is when it gets to
the datasource object (cmbClient.DataSource = ds), it immediately goes
to the event handler (SelectedIndexChanged), which later causes an
error. This is my code:

   Private Sub PopulateClient()
       Dim sqlConn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

       Try
           Dim ds As New DataSet("ds")
           Dim objDataAdapter As SqlDataAdapter = New SqlDataAdapter
           Dim cmd As SqlCommand = New SqlCommand("SELECT ClientName
FROM tblClients", sqlConn)

           sqlConn.Open()

           objDataAdapter.SelectCommand = cmd
           objDataAdapter.Fill(ds, "Clients")

           'Set up the Combobox bindings
           cmbClient.DataSource = ds
           cmbClient.SelectedIndex = 0
           cmbClient.DisplayMember = "Clients.ClientName"

       Catch ex As Exception
           'Error Handler
           lblError.Visible = True
           lblError.Text = Err.Description()
       Finally
           'Close the connection.
           sqlConn.Close()
       End Try
   End Sub

   Private Sub cmbClient_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbClient.SelectedIndexChanged
       Call PopulateEntity(cmbEntity.SelectedValue)
   End Sub

Any suggestions??
RobinS - 31 Jan 2007 23:22 GMT
You're saying that as you populate your combobox, it fires the
SelectedIndexChanged event, right?

I would put a boolean in there outside the PopulateClient sub, called
something like "_Loading".

In PopulateClient, set it to True at the beginning, and False at the end.

In the SelectedIndexChanged routine, check the boolean, and if _Loading is
true, don't do anything.

You can also remove the event handler for the SelectedIndexChanged event
before you start to load the data, then put it back after loading, but I
think it's kind of a pain.

Robin S.
-----------------------------------------

>I am trying to populate a combobox and then fire an indexchanged event
> handler.  My combobox populates fine, the problem is when it gets to
[quoted text clipped - 39 lines]
>
> Any suggestions??
Stoitcho Goutsev (100) - 01 Feb 2007 15:35 GMT
My suggestion is to wire the event after you set the data source.

Signature

HTH
Stoitcho Goutsev (100)

>I am trying to populate a combobox and then fire an indexchanged event
> handler.  My combobox populates fine, the problem is when it gets to
[quoted text clipped - 39 lines]
>
> Any suggestions??

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.