Force Listbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randy

    #1

    Force Listbox

    I have button that deletes items from a SQL datatable. The items are
    displayed for the user in listbox, which is bound to the dataset. The
    code works just fine insofar as it deletes the correct record from the
    dataset and the datasource. What I need to make it do is to refresh
    the listbox so that it reflects that the record has been deleted.
    Right now, the listbox removes the first item from the list and leaves
    the deleted item displayed. If I close the form and reopen it, all
    appears as it should (e.g. the correct item is gone and the listbox
    displays correctly). How can I force the listbox to refresh as if the
    form were re-loading.?

    Here is the code:

    Dim strSQL As String
    strSQL = "DELETE Category WHERE Category = @Cat"
    Dim cmdDelete As New SqlCommand(strS QL, cn)
    cmdDelete.Param eters.AddWithVa lue("@Cat",
    lbCat.SelectedV alue)

    Try
    cn.Open()
    Dim intRecordsAffec ted As Integer
    intRecordsAffec ted = cmdDelete.Execu teNonQuery()
    If intRecordsAffec ted = 1 Then
    CategoryBinding Source.RemoveCu rrent()
    CategoryBinding Source.MoveFirs t()

    End If
    Catch ex As Exception
    MessageBox.Show (ex.Message)
    Finally
    cn.Close()
    End Try

    Thanks a lot,
    Randy

  • Cor Ligthert [MVP]

    #2
    Re: Force Listbox

    Randy,

    Know that there is a big difference between "removing" and "deleting" in
    AdoNet

    Removing is actual removing the row.
    Deleting is setting the rowstate to delete (where needed, by row with
    rowstate new it is removing).

    After an update or an acceptchanges rows with rowstate delete are removed.

    Cor

    "Randy" <spam.eastland@ gmail.comschree f in bericht
    news:1179442426 .643029.137130@ u30g2000hsc.goo glegroups.com.. .
    >I have button that deletes items from a SQL datatable. The items are
    displayed for the user in listbox, which is bound to the dataset. The
    code works just fine insofar as it deletes the correct record from the
    dataset and the datasource. What I need to make it do is to refresh
    the listbox so that it reflects that the record has been deleted.
    Right now, the listbox removes the first item from the list and leaves
    the deleted item displayed. If I close the form and reopen it, all
    appears as it should (e.g. the correct item is gone and the listbox
    displays correctly). How can I force the listbox to refresh as if the
    form were re-loading.?
    >
    Here is the code:
    >
    Dim strSQL As String
    strSQL = "DELETE Category WHERE Category = @Cat"
    Dim cmdDelete As New SqlCommand(strS QL, cn)
    cmdDelete.Param eters.AddWithVa lue("@Cat",
    lbCat.SelectedV alue)
    >
    Try
    cn.Open()
    Dim intRecordsAffec ted As Integer
    intRecordsAffec ted = cmdDelete.Execu teNonQuery()
    If intRecordsAffec ted = 1 Then
    CategoryBinding Source.RemoveCu rrent()
    CategoryBinding Source.MoveFirs t()
    >
    End If
    Catch ex As Exception
    MessageBox.Show (ex.Message)
    Finally
    cn.Close()
    End Try
    >
    Thanks a lot,
    Randy
    >

    Comment

    Working...