Selecting Items at same index in Multiple Lists

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1554 Views - Last Post: 10 April 2012 - 12:26 PM Rate Topic: -----

#1 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Selecting Items at same index in Multiple Lists

Posted 06 April 2012 - 12:07 PM

I am working on a project for software engineering where we are trying to create a warehouse inventory system. I have created an inventory page where I can add/delete/search for an item as well as access invoices and reorder items...
i am struggling on the delete item part.
I have my design set up where there are four different lists on my page. One for name, one for serial number, one for RFID number and one for amount in stock. I want to be able to select an item by name and its information in serial number, rfid, and amount also select and have no idea how to go about this.. please help... I wanted to use four different lists because I need to be able to delete an item from the list and it remove just one from that stock and not the entire item unless there is only one of that item left in stock.

for my inventory page
Public Class InventoryDepartment

    Private Sub InventoryDepartment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'add items to name list
        Me.ListName.Items.Add("Item1")
        Me.ListName.Items.Add("Item2")
        Me.ListName.Items.Add("Item3")
        Me.ListName.Items.Add("Item4")
        Me.ListName.Items.Add("Item5")
        Me.ListName.Items.Add("Item6")
        Me.ListName.Items.Add("Item7")
        Me.ListName.Items.Add("Item8")
        Me.ListName.Items.Add("Item9")
        Me.ListName.Items.Add("Item10")
        
        'add items to serial list
        Me.ListSerial.Items.Add("1")
        Me.ListSerial.Items.Add("2")
        Me.ListSerial.Items.Add("3")
        Me.ListSerial.Items.Add("4")
        Me.ListSerial.Items.Add("5")
        Me.ListSerial.Items.Add("6")
        Me.ListSerial.Items.Add("7")
        Me.ListSerial.Items.Add("8")
        Me.ListSerial.Items.Add("9")
        Me.ListSerial.Items.Add("10")

        'add items to RFID list
        Me.ListRFID.Items.Add("1111")
        Me.ListRFID.Items.Add("2222")
        Me.ListRFID.Items.Add("3333")
        Me.ListRFID.Items.Add("4444")
        Me.ListRFID.Items.Add("5555")
        Me.ListRFID.Items.Add("6666")
        Me.ListRFID.Items.Add("7777")
        Me.ListRFID.Items.Add("8888")
        Me.ListRFID.Items.Add("9999")
        Me.ListRFID.Items.Add("10101010")

        'add items to amount
        Me.ListAmount.Items.Add("123")
        Me.ListAmount.Items.Add("456")
        Me.ListAmount.Items.Add("789")
        Me.ListAmount.Items.Add("987")
        Me.ListAmount.Items.Add("654")
        Me.ListAmount.Items.Add("321")
        Me.ListAmount.Items.Add("0")
        Me.ListAmount.Items.Add("25")
        Me.ListAmount.Items.Add("123535")
        Me.ListAmount.Items.Add("1239090")


       'select items in each list
        ListName.Select()
        ListSerial.Select()
        ListRFID.Select()
        ListAmount.Select()

    End Sub

    Private Sub AddItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddItemToolStripMenuItem.Click
        NewItem.Show()
    End Sub

    Private Sub DeleteItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteItemToolStripMenuItem.Click
        'Me.ListName.Items.Remove(Me.ListName.SelectedItems)
    End Sub

    Private Sub ReorderItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReorderItemToolStripMenuItem.Click
        Accounting.Show()
        Me.Close()
    End Sub

    Private Sub InvoiceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InvoiceToolStripMenuItem.Click
        InvoicesAvailable.Show()
        Me.Close()
    End Sub

    Private Sub SearchItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchItemToolStripMenuItem.Click
        ItemSearch.Show()
    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Selecting Items at same index in Multiple Lists

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: Selecting Items at same index in Multiple Lists

Posted 06 April 2012 - 12:15 PM

ListSerial1.SelectedIndex = listName.SelectedIndex should work. Just repeat that same method for the other lists. Do this in the selectedindex changed event I think should automatically select them.

Quote

I wanted to use four different lists because I need to be able to delete an item from the list and it remove just one from that stock and not the entire item unless there is only one of that item left in stock.

Have you thought of using a listview where you can have a column for each of these and then maybe a context menu to remove a quantity and just update the quantity on the row you have selected?

This post has been edited by CharlieMay: 06 April 2012 - 12:21 PM

Was This Post Helpful? 1
  • +
  • -

#3 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 832
  • Joined: 21-December 11

Re: Selecting Items at same index in Multiple Lists

Posted 06 April 2012 - 12:15 PM

you want to delete selected item?
you can find selected item in selecteditems collection.
If you select only one item,it means ,your selected item index is 0.
DeleteItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteItemToolStripMenuItem.Click

'use
Me.ListName.Items.RemoveAt(Me.ListName.SelectedItems(0).Index)
'or	       Me.ListName.Items.Remove(Me.ListName.SelectedItems(0))
	    End Sub

Was This Post Helpful? 0
  • +
  • -

#4 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Re: Selecting Items at same index in Multiple Lists

Posted 06 April 2012 - 12:22 PM

View Postsela007, on 06 April 2012 - 07:15 PM, said:

you want to delete selected item?
you can find selected item in selecteditems collection.
If you select only one item,it means ,your selected item index is 0.
DeleteItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteItemToolStripMenuItem.Click

'use
Me.ListName.Items.RemoveAt(Me.ListName.SelectedItems(0).Index)
'or	       Me.ListName.Items.Remove(Me.ListName.SelectedItems(0))
	    End Sub



________________________________________________________________________________________________________________________
ok but I want it so that when I click this "items name" it also selects the serial number, rfid number and amount in stock that corresponds with this item. And I want to be able to delete items so that if there are 436 items and I hit delete it changes it to 435 items and if there is 1 item left that it shows "out of stock" next to the item.... hope this makes sense....
Was This Post Helpful? 0
  • +
  • -

#5 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Re: Selecting Items at same index in Multiple Lists

Posted 06 April 2012 - 01:06 PM

View PostCharlieMay, on 06 April 2012 - 07:15 PM, said:

ListSerial1.SelectedIndex = listName.SelectedIndex should work. Just repeat that same method for the other lists. Do this in the selectedindex changed event I think should automatically select them.

Quote

I wanted to use four different lists because I need to be able to delete an item from the list and it remove just one from that stock and not the entire item unless there is only one of that item left in stock.

Have you thought of using a listview where you can have a column for each of these and then maybe a context menu to remove a quantity and just update the quantity on the row you have selected?



I did it as a list view but changed it so that the view setting is on list... what should i change it to??? and how would i use the context menu to update so that when i delete an item it just removes one from the item... for example:
if it has 236 and i click delete, I want it to have 235 listed under amount
Was This Post Helpful? 0
  • +
  • -

#6 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 832
  • Joined: 21-December 11

Re: Selecting Items at same index in Multiple Lists

Posted 06 April 2012 - 08:41 PM

OK,just focus on post #2 from CharlieMay. Instead of four lists you can use one listview. First,set listview property 'view' = 'details'. Then go to 'columns' property/collection (dblclick),and add four columns.
then you can add items :
        Dim lvItem As New ListViewItem

        lvItem = LV1.Items.Add("item1")
        lvItem.SubItems.Add("1") 
        lvItem.SubItems.Add("111")
        lvItem.SubItems.Add("123")

        lvItem = LV1.Items.Add("item2")
        lvItem.SubItems.Add("2")
        lvItem.SubItems.Add("222")
        lvItem.SubItems.Add("456")

Was This Post Helpful? 1
  • +
  • -

#7 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Re: Selecting Items at same index in Multiple Lists

Posted 09 April 2012 - 01:24 PM

View Postsela007, on 07 April 2012 - 03:41 AM, said:

OK,just focus on post #2 from CharlieMay. Instead of four lists you can use one listview. First,set listview property 'view' = 'details'. Then go to 'columns' property/collection (dblclick),and add four columns.
then you can add items :
        Dim lvItem As New ListViewItem

        lvItem = LV1.Items.Add("item1")
        lvItem.SubItems.Add("1") 
        lvItem.SubItems.Add("111")
        lvItem.SubItems.Add("123")

        lvItem = LV1.Items.Add("item2")
        lvItem.SubItems.Add("2")
        lvItem.SubItems.Add("222")
        lvItem.SubItems.Add("456")




ok I got that set up and it works perfectly.I also got my add button working correctly. Now, one more question... if I wanted to delete an item but not completely delete the item just delete a certain amount from that item, how would I do that... for example... i want to take item1 and delete 12 from it leaving 111 left instead of 123... how would i do that??
Was This Post Helpful? 0
  • +
  • -

#8 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 95
  • View blog
  • Posts: 882
  • Joined: 15-October 10

Re: Selecting Items at same index in Multiple Lists

Posted 09 April 2012 - 01:29 PM

You would need to get the value of that index then edit the value then re-save it to the the index that it came from.

so this will help you get started

Dim x as string = ""
x = ListBox1.SelectedItem.ToString


So the code above will make x the value of the item selected in the list box so then edit x then re-save it to the index it came from

Spoiler

This post has been edited by m_wylie85: 09 April 2012 - 02:00 PM

Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: Selecting Items at same index in Multiple Lists

Posted 09 April 2012 - 02:04 PM

OK. The listviewitem has .Text properties that you can work with
ListView1.FocusedItem.Text is the first column
ListView1.FocusedItem.SubItem(1).Text is the 2nd column

With this of course, FocusedItem is the row that is hilighted.

Now if you know that column(3) is a value of say 10

You can pull it into a numerical type and subtract 1 from it.
In your delete button
ListView1.FocusedItem.SubItem(2).Text = CDouble(ListView1.FocusedItem.SubItem(2).Text)-1


This is taking the value of the column, casting it to Double, subtracting 1 and putting the new value right back in the column.

This post has been edited by CharlieMay: 09 April 2012 - 02:05 PM

Was This Post Helpful? 0
  • +
  • -

#10 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Re: Selecting Items at same index in Multiple Lists

Posted 09 April 2012 - 02:18 PM

View Postm_wylie85, on 09 April 2012 - 08:29 PM, said:

You would need to get the value of that index then edit the value then re-save it to the the index that it came from.

so this will help you get started

Dim x as string = ""
x = ListBox1.SelectedItem.ToString


So the code above will make x the value of the item selected in the list box so then edit x then re-save it to the index it came from

Spoiler


  Dim x As String = ""
        x = LView.SelectedItems.ToString
        Dim y As New Integer
        y = x - (Me.AmountText.Text)

        Dim NewList As New ListViewItem
        NewList = LView.Items.Add("")
        NewList.SubItems.Add("")
        NewList.SubItems.Add("")
        NewList.SubItems.Add(y)



I took a selected item and saved it in x. Then took an amount entered in a text box called AmountText and subtracted that from x and then tried to resave it in the subitems of the list... BUT i am sure this is all wrong...

do i need to convert y back to a integer or something before subtracting the two.. also not sure how to save it back into the same form without altering what is entered in the fields under name, serial, rfid without having to reenter all that information... hope this makes sense
Was This Post Helpful? 0
  • +
  • -

#11 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 95
  • View blog
  • Posts: 882
  • Joined: 15-October 10

Re: Selecting Items at same index in Multiple Lists

Posted 09 April 2012 - 02:32 PM

whoops are working with Access?. If yes sorry i misread the post i thought you where working with list boxes :stupid:. If you are working with listboxes have a look at my spoiler and if you need to convert string to in int use try parse also listen to Charlie he is obviously better code than me

This post has been edited by m_wylie85: 09 April 2012 - 02:32 PM

Was This Post Helpful? 0
  • +
  • -

#12 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Re: Selecting Items at same index in Multiple Lists

Posted 09 April 2012 - 02:36 PM

Nevermind, I got the coding to work for me in the delete department. It is working very well. Thankyou for all your help.

Is there a certain way to make it so that when I click in the name department and it selects "item1" that it also selects its serial, rfid and amount too so that they are all highlighted??
Was This Post Helpful? 0
  • +
  • -

#13 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Re: Selecting Items at same index in Multiple Lists

Posted 10 April 2012 - 08:06 AM

One last issue, hopefully.. I am trying to create a search field so that when an item is entered into the text box present and the search button pressed that it either highlights the item or moves the item to the top of the list...here is what i have:

Dim foundItem As ListViewItem = ListView1.FindItemWithText(Me.searchText.Text, False, 0, True)

   If (foundItem IsNot Nothing) Then
    ListView1.TopItem = foundItem
   End If


Was This Post Helpful? 0
  • +
  • -

#14 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: Selecting Items at same index in Multiple Lists

Posted 10 April 2012 - 08:47 AM

Are you wanting to MOVE it to the top, or have it come into view of the visible list?

What you have should bring the founditem into view in your listview.
Was This Post Helpful? 0
  • +
  • -

#15 SnoBunny85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Re: Selecting Items at same index in Multiple Lists

Posted 10 April 2012 - 09:57 AM

View PostCharlieMay, on 10 April 2012 - 03:47 PM, said:

Are you wanting to MOVE it to the top, or have it come into view of the visible list?

What you have should bring the founditem into view in your listview.



I would like to bring it to the top that way I know it has been searched for... how would I go about doing that??
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2