ARTICLE

Drag records from one Listbox to other one in VB.NET

Posted by Satyapriya Nayak Articles | ASP.NET using VB.NET August 10, 2011
In this article I will show you how to drag records from one listbox to another one and vice versa.
Download Files:
 
Reader Level:

In this article I will show you how to drag records from one listbox to another one and vice versa. Here we can drag records by selecting it by one by one and also can drag all records from one listbox to another and vice versa.

Program

Default.aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    </div>

    <asp:ListBox ID="ListBox1" runat="server" Width="134px" Height="116px"></asp:ListBox>

    <asp:Button ID="Button1" runat="server" Text="&lt;|" />

   <asp:Button ID="Button2" runat="server" Text="|&gt;" />

   <asp:Button ID="Button3" runat="server" Text="&lt;&lt;|" />

   <asp:Button ID="Button4" runat="server" Text="|&gt;&gt;" />

    <asp:ListBox ID="ListBox2" runat="server" Width="134px" Height="116px"></asp:ListBox>

    </form>

</body>

</html>

Default.aspx.vb code

Partial Class _Default

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            ListBox1.Items.Add("Raj")

            ListBox1.Items.Add("Ravi")

            ListBox1.Items.Add("Rahul")

            ListBox1.Items.Add("Raju")

            ListBox1.Items.Add("Rohit")

            ListBox1.Items.Add("Rajesh")

        End If

    End Sub

 

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        ListBox1.Items.Add(ListBox2.SelectedItem.Text)

        Dim i As Integer

        i = ListBox2.SelectedIndex

        ListBox2.Items.RemoveAt(i)

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        ListBox2.Items.Add(ListBox1.SelectedItem.Text)

        Dim i As Integer

        i = ListBox1.SelectedIndex

        ListBox1.Items.RemoveAt(i)

    End Sub

 

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim j As Integer

        For j = 0 To ListBox2.Items.Count - 1

            ListBox1.Items.Add(ListBox2.Items(j))

        Next

        ListBox2.Items.Clear()

    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim j As Integer

        For j = 0 To ListBox1.Items.Count - 1

            ListBox2.Items.Add(ListBox1.Items(j))

        Next

        ListBox1.Items.Clear()

    End Sub

End Class

Output

satya1.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor