Why is this event firing?

G

Guest

Hey all,


I've the following code:

Dim _postBack As Boolean = False
Dim _ds As New DataSet1
Dim _dt As DataSet1.CustomersDataTable
Dim _dr As DataSet1.CustomersRow

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(_ds)
_dt = _ds.Customers
ListBox1.DataSource = _dt
ListBox1.DisplayMember = "ContactName"
ListBox1.ValueMember = "CustomerID"
_postBack = True
End Sub

Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ListBox1.SelectedValueChanged
If _postBack = True Then
MessageBox.Show("Finding customer...")
_dr = _dt.FindByCustomerID(ListBox1.SelectedValue)
TextBox1.Text = _dr.ContactName
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
_dr.ContactName = TextBox1.Text
MessageBox.Show(_dr.RowState.ToString)
End Sub

Why?, when I click the Button1, does the ListBox1_SelectedValueChanged run?

To recreate:
All you need is Northwind.
I used the SqlDataAdapter wizard
Generated a typedDataset(no instance)
 
I

Imran Koradia

Is this an ASP.NET project? I'm not sure what the _postBack flag does. Is
this a variable you've created? If you are using the variable for something
else then I would suggest you create a new variable as mentioned in the link
I sent. Any reason why you cant do it that way?

Imran.
 
C

Cor Ligthert

Rodchar,

I have looked at your code, without testing it, had no time anymore to do it
real good, and therefore I did want to try it today, however I see now that
your question is resolved.

About the postback my question was exactly the same as from Imran even
before you posted this message.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top