środa, 28 października 2009

cd... from listbox to listbox w ASP. NET (VB) czyli jak ... z jednej kontrolki do drugiej, tam i z powrotem

Kod VB:
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btnToRight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnToRight.Click
        Dim itemsToRemove As New List(Of ListItem)

        'loop through the selected items of the first listbox and add them to the second listbox
        For Each item As ListItem In ListBox1.Items
            If item.Selected And Not ListBox2.Items.Contains(item) Then
                Dim newItem As New ListItem(item.Text, item.Value)
                ListBox2.Items.Add(newItem)
                itemsToRemove.Add(item)
            End If
        Next

        'loop through removed items collection and remove the items from first listbox
        For Each item As ListItem In itemsToRemove
            ListBox1.Items.Remove(item)
        Next
    End Sub

    Protected Sub btnToLeft_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnToLeft.Click
        Dim itemsToRemove As New List(Of ListItem)
        'loop through the selected items of the second listbox and add them to the first listbox
        For Each item As ListItem In ListBox2.Items
            If item.Selected And Not ListBox1.Items.Contains(item) Then
                Dim newItem As New ListItem(item.Text, item.Value)
                ListBox1.Items.Add(newItem)
                itemsToRemove.Add(item)
            End If
        Next

        'loop through removed items collection and remove the items from first listbox
        For Each item As ListItem In itemsToRemove
            ListBox2.Items.Remove(item)
        Next
    End Sub
End Class

wtorek, 20 października 2009

From listbox to listbox w ASP. NET (VB) czyli jak przenieść informację z jednej do drugiej

Kontrolki:
Listbox1
Button1
Listbox2

Kod (na razie bez usuwania danych z Listbox2):
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        For i = 0 To ListBox1.Items.Count - 1
            If ListBox1.Items(i).Selected Then
                ListBox2.Items.Add(ListBox1.Items(i).Text)
            End If
        Next
    End Sub

poniedziałek, 19 października 2009

Pierwszy

Jakiś początek być musi...
... lepszy taki niż żaden...
Chociaż ten jest bez sensu ...