473,508 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(strSQL, cn)
cmdDelete.Parameters.AddWithValue("@Cat",
lbCat.SelectedValue)

Try
cn.Open()
Dim intRecordsAffected As Integer
intRecordsAffected = cmdDelete.ExecuteNonQuery()
If intRecordsAffected = 1 Then
CategoryBindingSource.RemoveCurrent()
CategoryBindingSource.MoveFirst()

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

Thanks a lot,
Randy

May 17 '07 #1
1 1418
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" <sp***********@gmail.comschreef in bericht
news:11**********************@u30g2000hsc.googlegr oups.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(strSQL, cn)
cmdDelete.Parameters.AddWithValue("@Cat",
lbCat.SelectedValue)

Try
cn.Open()
Dim intRecordsAffected As Integer
intRecordsAffected = cmdDelete.ExecuteNonQuery()
If intRecordsAffected = 1 Then
CategoryBindingSource.RemoveCurrent()
CategoryBindingSource.MoveFirst()

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

Thanks a lot,
Randy

May 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
3089
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
3590
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
3
5262
by: Bernardo | last post by:
Hi, Hi have a Listbox whith some values but I want to select the first line and execute the routine on_click. I selected allready the list value, but how can Y force the click event? Thanks...
6
2858
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
7
4518
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
6
2398
by: Shawn | last post by:
Any ideas how I can have a button click on one open page force a postback on a different page.
3
2272
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
5
20149
by: Randy | last post by:
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...
3
3770
by: e | last post by:
I have a form which includes a list box populated with items from a query. When a user double clicks on a row in the list box, each column item is put into a specific text box. The problem...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.