Listbox.Remove method 
Author Message
 Listbox.Remove method

I created a number of objects and added those objects to a list box.  Now
when I attempt to use the remove method, it seems to function, but when the
form is displayed back, the item is not removed,  What gives?  Is there
something more that I need to do to get it out of the listbox?

Your assistance is greatly appreciated!



Sun, 17 Apr 2005 04:28:11 GMT  
 Listbox.Remove method
It sounds like you may be using the properties window to define the listbox
entries and then using code to remove an item.  If that is the case, when
you create a new instance of the form it will grab all the values from your
design-time settings in the property grid.  You will need to remove the
values from the property grid in design-mode.

Dave & Jim
VB .NET Development

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I created a number of objects and added those objects to a list box.  Now
> when I attempt to use the remove method, it seems to function, but when
the
> form is displayed back, the item is not removed,  What gives?  Is there
> something more that I need to do to get it out of the listbox?

> Your assistance is greatly appreciated!



Sun, 17 Apr 2005 05:46:52 GMT  
 Listbox.Remove method
I am adding the entries to the listbox via code and I am removing them by
code.   The code to add the entries is as follows (pulling the entries from
the DataSet - building my object - and then adding the object to the
Listbox:

Do Until i = DsStockData2.Tables("Company").Rows.Count()

    Dim obj As StockData

   Dim exch As Integer

   If DsStockData2.Tables("Company").Rows(i).Item("Exchange") Is
DBNull.Value Then

       exch = 0

   Else

       exch = DsStockData2.Tables("Company").Rows(i).Item("Exchange")

   End If

   obj = New
StockData(DsStockData2.Tables("Company").Rows(i).Item("Comp_ID"), _

                     DsStockData2.Tables("Company").Rows(i).Item("Name"), _

                     DsStockData2.Tables("Company").Rows(i).Item("Symbol"),
_

                    exch, _

DsStockData2.Tables("Company").Rows(i).Item("TotalHeld"))

   lstCompanyNames.Items.Add(obj)

   i += 1

Loop

Here is the code to remove the item from the listbox....

MsgBox("Total items before the delete of item in listbox = " &
lstCompanyNames.Items.Count)

lstCompanyNames.Items.Remove(lstCompanyNames.SelectedIndex)

MsgBox("Total items now in the listbox = " & lstCompanyNames.Items.Count)

The row count before the delete is 12 and the rowcount after the delete is
12.



Quote:
> It sounds like you may be using the properties window to define the
listbox
> entries and then using code to remove an item.  If that is the case, when
> you create a new instance of the form it will grab all the values from
your
> design-time settings in the property grid.  You will need to remove the
> values from the property grid in design-mode.

> Dave & Jim
> VB .NET Development

> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.



> > I created a number of objects and added those objects to a list box.
Now
> > when I attempt to use the remove method, it seems to function, but when
> the
> > form is displayed back, the item is not removed,  What gives?  Is there
> > something more that I need to do to get it out of the listbox?

> > Your assistance is greatly appreciated!



Sun, 17 Apr 2005 08:50:25 GMT  
 Listbox.Remove method
I wouldn't swear that this is your solution, but are you using an underlying
datatable as the source for the listbox, you'd have to delete the record
from the underlying datatable and perform and update before the item would
be omitted.  I may be reading this too simplistically tho...

--- Jim ---


Quote:
> I am adding the entries to the listbox via code and I am removing them by
> code.   The code to add the entries is as follows (pulling the entries
from
> the DataSet - building my object - and then adding the object to the
> Listbox:

> Do Until i = DsStockData2.Tables("Company").Rows.Count()

>     Dim obj As StockData

>    Dim exch As Integer

>    If DsStockData2.Tables("Company").Rows(i).Item("Exchange") Is
> DBNull.Value Then

>        exch = 0

>    Else

>        exch = DsStockData2.Tables("Company").Rows(i).Item("Exchange")

>    End If

>    obj = New
> StockData(DsStockData2.Tables("Company").Rows(i).Item("Comp_ID"), _

>                      DsStockData2.Tables("Company").Rows(i).Item("Name"),
_

DsStockData2.Tables("Company").Rows(i).Item("Symbol"),

- Show quoted text -

Quote:
> _

>                     exch, _

> DsStockData2.Tables("Company").Rows(i).Item("TotalHeld"))

>    lstCompanyNames.Items.Add(obj)

>    i += 1

> Loop

> Here is the code to remove the item from the listbox....

> MsgBox("Total items before the delete of item in listbox = " &
> lstCompanyNames.Items.Count)

> lstCompanyNames.Items.Remove(lstCompanyNames.SelectedIndex)

> MsgBox("Total items now in the listbox = " & lstCompanyNames.Items.Count)

> The row count before the delete is 12 and the rowcount after the delete is
> 12.



> > It sounds like you may be using the properties window to define the
> listbox
> > entries and then using code to remove an item.  If that is the case,
when
> > you create a new instance of the form it will grab all the values from
> your
> > design-time settings in the property grid.  You will need to remove the
> > values from the property grid in design-mode.

> > Dave & Jim
> > VB .NET Development

> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.



> > > I created a number of objects and added those objects to a list box.
> Now
> > > when I attempt to use the remove method, it seems to function, but
when
> > the
> > > form is displayed back, the item is not removed,  What gives?  Is
there
> > > something more that I need to do to get it out of the listbox?

> > > Your assistance is greatly appreciated!



Sun, 17 Apr 2005 23:52:41 GMT  
 Listbox.Remove method
I do have a data table which provides the information that I am using to
build my objects, but then after that, there is no relationship between my
data tables and the list box.  If I had bound my datatable to the list box
control, then, as you have suggested, the problem would be in deleting the
row from the datatable and then that supposidly would have made the list box
correct.....but this is not the situation!

Still lost to explain why the row still remains....


Quote:
> I wouldn't swear that this is your solution, but are you using an
underlying
> datatable as the source for the listbox, you'd have to delete the record
> from the underlying datatable and perform and update before the item would
> be omitted.  I may be reading this too simplistically tho...

> --- Jim ---



> > I am adding the entries to the listbox via code and I am removing them
by
> > code.   The code to add the entries is as follows (pulling the entries
> from
> > the DataSet - building my object - and then adding the object to the
> > Listbox:

> > Do Until i = DsStockData2.Tables("Company").Rows.Count()

> >     Dim obj As StockData

> >    Dim exch As Integer

> >    If DsStockData2.Tables("Company").Rows(i).Item("Exchange") Is
> > DBNull.Value Then

> >        exch = 0

> >    Else

> >        exch = DsStockData2.Tables("Company").Rows(i).Item("Exchange")

> >    End If

> >    obj = New
> > StockData(DsStockData2.Tables("Company").Rows(i).Item("Comp_ID"), _

DsStockData2.Tables("Company").Rows(i).Item("Name"),

- Show quoted text -

Quote:
> _

> DsStockData2.Tables("Company").Rows(i).Item("Symbol"),
> > _

> >                     exch, _

> > DsStockData2.Tables("Company").Rows(i).Item("TotalHeld"))

> >    lstCompanyNames.Items.Add(obj)

> >    i += 1

> > Loop

> > Here is the code to remove the item from the listbox....

> > MsgBox("Total items before the delete of item in listbox = " &
> > lstCompanyNames.Items.Count)

> > lstCompanyNames.Items.Remove(lstCompanyNames.SelectedIndex)

> > MsgBox("Total items now in the listbox = " &

lstCompanyNames.Items.Count)

- Show quoted text -

Quote:

> > The row count before the delete is 12 and the rowcount after the delete
is
> > 12.



> > > It sounds like you may be using the properties window to define the
> > listbox
> > > entries and then using code to remove an item.  If that is the case,
> when
> > > you create a new instance of the form it will grab all the values from
> > your
> > > design-time settings in the property grid.  You will need to remove
the
> > > values from the property grid in design-mode.

> > > Dave & Jim
> > > VB .NET Development

> > > --
> > > This posting is provided "AS IS" with no warranties, and confers no
> > rights.



> > > > I created a number of objects and added those objects to a list box.
> > Now
> > > > when I attempt to use the remove method, it seems to function, but
> when
> > > the
> > > > form is displayed back, the item is not removed,  What gives?  Is
> there
> > > > something more that I need to do to get it out of the listbox?

> > > > Your assistance is greatly appreciated!



Mon, 18 Apr 2005 05:12:11 GMT  
 Listbox.Remove method
OK, I figured it out.  The "Remove" method apparently wants the value to be
removed and not the index which contains the value to be removed.  I would
have thought that the method would a failed or something along those lines
if you attempted to remove something which was not there, but that
apparently is not the case.

The RemoveAt version provides for you to delete a specified item based upon
the index.  I will use this method.

So I found my error.

Thanks for everyone's assistance.


Quote:
> I do have a data table which provides the information that I am using to
> build my objects, but then after that, there is no relationship between my
> data tables and the list box.  If I had bound my datatable to the list box
> control, then, as you have suggested, the problem would be in deleting the
> row from the datatable and then that supposidly would have made the list
box
> correct.....but this is not the situation!

> Still lost to explain why the row still remains....



> > I wouldn't swear that this is your solution, but are you using an
> underlying
> > datatable as the source for the listbox, you'd have to delete the record
> > from the underlying datatable and perform and update before the item
would
> > be omitted.  I may be reading this too simplistically tho...

> > --- Jim ---



> > > I am adding the entries to the listbox via code and I am removing them
> by
> > > code.   The code to add the entries is as follows (pulling the entries
> > from
> > > the DataSet - building my object - and then adding the object to the
> > > Listbox:

> > > Do Until i = DsStockData2.Tables("Company").Rows.Count()

> > >     Dim obj As StockData

> > >    Dim exch As Integer

> > >    If DsStockData2.Tables("Company").Rows(i).Item("Exchange") Is
> > > DBNull.Value Then

> > >        exch = 0

> > >    Else

> > >        exch = DsStockData2.Tables("Company").Rows(i).Item("Exchange")

> > >    End If

> > >    obj = New
> > > StockData(DsStockData2.Tables("Company").Rows(i).Item("Comp_ID"), _

> DsStockData2.Tables("Company").Rows(i).Item("Name"),
> > _

> > DsStockData2.Tables("Company").Rows(i).Item("Symbol"),
> > > _

> > >                     exch, _

> > > DsStockData2.Tables("Company").Rows(i).Item("TotalHeld"))

> > >    lstCompanyNames.Items.Add(obj)

> > >    i += 1

> > > Loop

> > > Here is the code to remove the item from the listbox....

> > > MsgBox("Total items before the delete of item in listbox = " &
> > > lstCompanyNames.Items.Count)

> > > lstCompanyNames.Items.Remove(lstCompanyNames.SelectedIndex)

> > > MsgBox("Total items now in the listbox = " &
> lstCompanyNames.Items.Count)

> > > The row count before the delete is 12 and the rowcount after the
delete
> is
> > > 12.



> > > > It sounds like you may be using the properties window to define the
> > > listbox
> > > > entries and then using code to remove an item.  If that is the case,
> > when
> > > > you create a new instance of the form it will grab all the values
from
> > > your
> > > > design-time settings in the property grid.  You will need to remove
> the
> > > > values from the property grid in design-mode.

> > > > Dave & Jim
> > > > VB .NET Development

> > > > --
> > > > This posting is provided "AS IS" with no warranties, and confers no
> > > rights.



> > > > > I created a number of objects and added those objects to a list
box.
> > > Now
> > > > > when I attempt to use the remove method, it seems to function, but
> > when
> > > > the
> > > > > form is displayed back, the item is not removed,  What gives?  Is
> > there
> > > > > something more that I need to do to get it out of the listbox?

> > > > > Your assistance is greatly appreciated!



Mon, 18 Apr 2005 13:16:11 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Remove Interface Methods from class methods

2. Remove selected item from listbox

3. removing file extension in listbox dir-overview

4. Could not remove item from listBox WinForm control

5. Removing a listbox item

6. Removing repeating items from ListBox

7. Newbie q: Remove selected items from multiselect listbox?

8. Removing item from ListBox control using ItemData

9. 2 listboxes to add/remove items from each other

10. Remove Highlighted Listbox Item?

11. Removing duplicates in listbox

12. How can I remove name from listbox

 

 
Powered by phpBB® Forum Software