Bindingsource Not updating listbox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcf
    New Member
    • Mar 2008
    • 17

    #1

    Bindingsource Not updating listbox?

    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.SqlCo mmand()
    With cmd


    .Connection = New SqlClient.SqlCo nnection("Data Source=MYSSERVE R;Initial Catalog=PGLCMS; Integrated Security=True")

    .CommandType = CommandType.Tex t
    .CommandText = "INSERT into Notes VALUES (" & Val(TextBox3.Te xt) & ",'" & Trim(TextBox2.T ext) & "','" & TextBox1.Text & "','" & Date.Now & "')"

    End With

    cmd.Connection. Open() '< Open it before executing the query
    cmd.ExecuteNonQ uery()
    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.NotesTabl eAdapter.Fill(F orm1.PGLCMSData Set.Notes)
    If Form1.RadioButt on1.Checked Then
    Form1.NotesTabl eAdapter.FillBy (Form1.PGLCMSDa taSet.Notes, Form1.ListBox1. ValueMember)
    ElseIf Form1.RadioButt on2.Checked Then
    Form1.NotesTabl eAdapter.FillBy 1(Form1.PGLCMSD ataSet.Notes, Val(Form1.Compa nyIDTextBox.Tex t))
    Else
    Form1.NotesTabl eAdapter.FillBy 1(Form1.PGLCMSD ataSet.Notes, Val(Form1.Compa nyIDTextBox.Tex t))
    End If
    Form1.NotesBind ingSource.Reset Item(Form1.Note sBindingSource. Current)
    Form1.ListBox2. DataSource = Form1.NotesBind ingSource
    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
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    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 :-)

    Comment

    Working...