Connecting Tech Pros Worldwide Help | Site Map

Bindingsource Not updating listbox?

Newbie
 
Join Date: Mar 2008
Posts: 17
#1: May 6 '08
Hi everyone,

I'm probably being dim here but here's my problem.

My main form opens a subform for a user to add notes, when they click save it does the following:

---------------------------Start Code -----------------------------------

Dim cmd As New SqlClient.SqlCommand()
With cmd


.Connection = New SqlClient.SqlConnection("Data Source=MYSSERVER;Initial Catalog=PGLCMS;Integrated Security=True")

.CommandType = CommandType.Text
.CommandText = "INSERT into Notes VALUES (" & Val(TextBox3.Text) & ",'" & Trim(TextBox2.Text) & "','" & TextBox1.Text & "','" & Date.Now & "')"

End With

cmd.Connection.Open() '< Open it before executing the query
cmd.ExecuteNonQuery()
cmd.Connection.Close() '< Close it after executing the query

cmd.Dispose()


-----------------------------------End Code------------------------------------------------------

This sticks the right record in the right place, then when I close the notes entering form I want my notes listbox to refresh itself and display new data. So I added the following code below the lot above:


-----------------------------------Start code------------------------------------------------------

Form1.NotesTableAdapter.Fill(Form1.PGLCMSDataSet.N otes)
If Form1.RadioButton1.Checked Then
Form1.NotesTableAdapter.FillBy(Form1.PGLCMSDataSet .Notes, Form1.ListBox1.ValueMember)
ElseIf Form1.RadioButton2.Checked Then
Form1.NotesTableAdapter.FillBy1(Form1.PGLCMSDataSe t.Notes, Val(Form1.CompanyIDTextBox.Text))
Else
Form1.NotesTableAdapter.FillBy1(Form1.PGLCMSDataSe t.Notes, Val(Form1.CompanyIDTextBox.Text))
End If
Form1.NotesBindingSource.ResetItem(Form1.NotesBind ingSource.Current)
Form1.ListBox2.DataSource = Form1.NotesBindingSource
Form1.listbox2.refresh()

-----------------------------------End Code------------------------------------------------------

Which does absolutely nothing, the new notes dont display until I use the binding navigator to move to the next record and back.

Any ideas?
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#2: May 6 '08

re: Bindingsource Not updating listbox?


Hi marcf,

If you place a breakpoint at the top of your second section of code does it fire?

Is this a windows app or a web page?

Dr B

PS Marc can you remember to use the code tags (the # button at the top of the posting box) to surround your code - it makes it much easier for everyone to read. Thanks :-)
Reply


Similar .NET Framework bytes