Friday, 23 May 2014

Remove Selected Item From Listbox C#.Net and VB.net

5/23/2014 - By Pranav Singh 0

In a Windows application are listbox control provide one of the most important part to provide data in a list format  In this article I will show you how you can remove selected item from  listbox c#.net and vb.net.

 Here is the article in which I have shown how to move single item at a time from one listbox to another listbox Transfer Listbox Items to Another Listbox Using C#.Net and VB.Net | How to Move List Box Items to another List Box in C# . For removing multiple selected item from list box here is the article How to add/move multiselected items from one listbox to another listbox in C#.Net and VB.Net  , C# multiple selection listbox move Using C#.Net.


So for this article first you create a new windows application and add listbox control and button control to remove the records.



Here is the code to remove selected item from listbox. In this we have written code on button click.
C#.Net
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace ProjectDemo_Windows
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnremove_Click(object sender, EventArgs e)
        {
            foreach (var item in new ArrayList(listBox1.SelectedItems))
            {
                listBox1.Items.Remove(item);
            }
        }
    }
}


VB.Net
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Collections

Namespace ProjectDemo_Windows
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub btnremove_Click(ByVal sender As Object, ByVal e As EventArgs)
            For Each item As var In New ArrayList(listBox1.SelectedItems)
                listBox1.Items.Remove(item)
            Next
        End Sub       
    End Class
End Namespace

In above code we have applied loop to check which item in selected and if it’s selected on that case we are removing item from listbox1.

So here is the final output:


DOWNLOAD
  

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top