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.
Some of the eBooks which you may also like to download :
How
to show error message in c# windows application | How to show Error &
Warning Message Box in .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
0 comments:
Please let me know your view