Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Gauge for SharePoint
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Remove duplicate items from listbox in .NET

 by Ankur Gupta on Jan 30, 2012

Learn here how to delete duplicate items from listbox in .NET.
Comments: 0 Views: 528 Printable Version 

Many times when we bind our controls from a non primary column of table then it may be a case that we got the duplicate records in our dataset. There is no sense to bind duplicate records without any identity value in any control.

With the help of the following function you can easily remove duplicate items from your Listbox control.

[VB.Net]

Private Sub RepoveDuplicate()
    For Row As Int16 = 0 To MyListBox.Items.Count - 2
        For RowAgain As Int16 = MyListBox.Items.Count - 1 To Row + 1 Step -1
            If MyListBox.Items(Row).ToString = MyListBox.Items(RowAgain).ToString
Then
                MyListBox.Items.RemoveAt(RowAgain)
            End
If
        Next
    Next
End Sub

[C#]

   
private void RepoveDuplicate()
    {
        for (Int16 Row = 0; Row <= MyListBox.Items.Count - 2; Row++)
        {
            for (Int16 RowAgain = MyListBox.Items.Count - 1; RowAgain >= Row + 1;
                 RowAgain += -1)
            {
                if (MyListBox.Items(Row).ToString == MyListBox.Items(RowAgain).ToString)
                {
                    MyListBox.Items.RemoveAt(RowAgain);
                }
            }
        }
    }
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: 29
Location:
Title: Project Manager
Joined: May 15, 2010
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.