Results 1 to 2 of 2

Thread: ListBox DataSet Urgent Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    1

    Arrow ListBox DataSet Urgent Problem

    I have two ListBoxes in my VB.Net Form.Each ListBox is connected to a DataSet.
    Between ListBoxes there are two Buttons .. You Know "<<" And ">>". I transfer data from ListBox to another by the following code:
    1. Get DataViiew of First ListBox . Then I Remove From It the Specific Item.
    2. Then Get a DataSet of the Deleted Changes in the First DataSet : Ds.getChanges(DataRowState.Deleted)
    3. Merge the Second DataSet of the Second ListBox to the Deleted Items DataSet..
    DS2.Merge(DataSet )
    All those Actions really Happen. It does transfer the item from one listbox to another..But it doesn't delete it from the First ListBox..
    When I try to delete an item from the ListBox..
    It Gives me an Error: That The ListBox Cannot Be Modified .. while the ListBox.DataSource is Set..
    If I set the ListBox.DataSource = Nothing to be able to change [delete] the item in the ListBox .. it removes all the items in the ListBox...How Could I delete the Items in the First ListBox that have been transferred to the other ListBox?

    How Could I delete the Items in the First ListBox that have been transferred to the other ListBox?
    Please It is a Very Fatal Problem For ME... I searched alot for an answer but couldn't find one.. Hope u can help me

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    i think u cannot delete if the datasource is set. that will result in deletion of records. i use the following code to move items within llistboxes.

    VB Code:
    1. Private Sub cmd_SelAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_SelAll.Click
    2.         List2.Items.AddRange(List1.Items)
    3.         List1.Items.Clear()
    4.     End Sub
    5.  
    6.     Private Sub cmd_Select_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Select.Click
    7.         Dim n As Short
    8.         For n = 0 To List1.Items.Count - 1
    9.             If List1.GetSelected(n) = True Then
    10.                 List2.Items.Add(List1.Items(n))
    11.             End If
    12.         Next
    13.  
    14.         n = 0
    15.         Do While n <= List1.Items.Count - 1
    16.             If List1.GetSelected(n) = True Then
    17.                 List1.Items.RemoveAt(n)
    18.                 n = n - 1
    19.             End If
    20.             n = n + 1
    21.         Loop
    22.         List1.Focus()
    23.     End Sub
    24.  
    25.     Private Sub cmd_Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Remove.Click
    26.         Dim n As Short
    27.         For n = 0 To List2.Items.Count - 1
    28.             If List2.GetSelected(n) = True Then
    29.                 List1.Items.Add(List2.Items(n))
    30.             End If
    31.         Next
    32.  
    33.         n = 0
    34.         Do While n <= List2.Items.Count - 1
    35.             If List2.GetSelected(n) = True Then
    36.                 List2.Items.RemoveAt(n)
    37.                 n = n - 1
    38.             End If
    39.             n = n + 1
    40.         Loop
    41.         List2.Focus()
    42.     End Sub
    43.  
    44.     Private Sub cmd_RemAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_RemAll.Click
    45.         List1.Items.AddRange(List2.Items)
    46.         List2.Items.Clear()
    47.     End Sub

    hope it helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width