VB.NET - Disable listbox selected items

Asked By Srinivasan S
13-Jun-11 01:16 AM
How can i disable selected items in listbox using vb.net?

Also,If I am loading the form again,it should not display the disable items in listbox. But i dont want to delete in database. Just want to disable or hide. That's it.

Help me
  Reena Jain replied to Srinivasan S
13-Jun-11 01:48 AM
hi,

You can copy your selectedItems to a temp object and then iterate the temp object (with foreach) and delete all matched listviewitems from listview. A simple eg for this

 

List<ListViewItem> templvi=new List<ListViewItem>();
templvi.AddRange(ListView.SelectedItems);
foreach(ListViewItem item in templvi)
{
ListView.Remove(item);
}

or you can use do while loop for this

Do
  ListBox1.Items.Remove(ListBox1.SelectedItem)
While (ListBox1.SelectedItems.Count > 0)

Hope this will help you
  pete rainbow replied to Srinivasan S
13-Jun-11 01:57 AM
also using a listview you could also have all items there and set the colour of those you don't want to be neabled to grey

and also handle the selection event and stop the ones you don't want to be selected

if you don't need the 'disabled' items to appear ever, then i'd just keep a list of those enabled and bind it to the listview

then updating the list will do the trick

google databinding to understand more on that, always better than doing it manually and copying etc and pretty essential in wpf world
  Anoop S replied to Srinivasan S
13-Jun-11 03:56 AM
The listbox is a little different from other controls. It doesn't allow for javascript to pick up the click event so a postback can't occur. So what happens is that the selectedindexchanged event is fired when the postback happens... whenever it does happen.

You can remove the item by generating javascript, yes.

On the page:


<script type="text/javascript">
    function removethis(listboxid)
    {
    var lbx = document.getElementById(listboxid);
      var selIndex = lbx.selectedIndex;
        if (selIndex != -1)
        {
        for(i=lbx.length-1; i>=0; i--)
        {
          if(lbx.options[i].selected)
          {
          document.getElementById(document.getElementById('Hidden1').value).value = lbx.options[lbx.selectedIndex].value;
          lbx.options[i] = null;
          }
        }
 
        }
      }
</script>

Code:

ListBox1.Attributes.Add("onclick", "removethis('" + ListBox1.ClientID + "');")
Create New Account
help
filelistbox .NET Framework Bonjour a tous. Sous vb.net 2008 Pour recupérer la liste des fichiers de mon repertoir j'utilise: filelistbox c'est un composant VB6 il me semble, y aurait il un composaznt vb.net qui fasse la meme chose? D'avance merci de votre aide VB.NET - French Discussions ListViewItem (1) DirectoryInfo (1) SearchOption (1) ListView (1) AddRange (1) GetFiles (1) Bonjour Dan, Voila le drame de tout codeur vb6: non
change the color in particular row in listview vb.net how to change the color in particular row in listview vb.net? Here i attached my listview data load coding. In given below code how to change the forecolor in all column or ) second row. Anybody pl.help me. . Dim strd(2) As String Dim itmd As ListViewItem If rs.State = 1 Then rs.Close() gssql = "select nCapaNo, cStatus, cSeverity from table" rs
images with name in vb.net VB.NET Hi, I want to show the list of images from my application folder and its name in listview control. When i click an image it should show the preview of that selected image How to do this in vb.net windows application. Please help me out. Thanks kiruba.e check this, http: / / www.dreamincode.net imgSize.Height = 150 ListView2.LargeImageList = _imgList Dim count As Integer = 0 Dim item As New ListViewItem For Each dirFile As String In dirFiles For Each extension As String In allowedExtensions If
Item Collection and a ListView (Vb.Net) Outlook I am using a ListView with checkboxes as a metaphor for working with a collection (MapiFolder.Items) of ContactItems in according to a user's input. I manually bind selected properties of (i.e. create ListViewItem and SubItems) this collection to the ListView, as there isn't a way to do this declaratively. I use the EntryId as the Tag for the ListViewItem. Currently, if I need to make change to a ContactItem that has been created in the ListView (e.g. changing the email address), I use the EntryID to locate the ContactItem in
Project guidelines I am going to start a simple project on vb.net with only 10 tables and 5 forms with sql knowledge and less knowledge on VB.Net plse give a example for doing single form with 10 necessarily used control for doing keeping this form as an reference. . .plse help me If you dont know about the VB.net application it self then I would suggest you to go and read some book on vb.net and get some idea on the control even you can learn the vb.net control