NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums General General Discussion v
« Previous 1 … 104 105 106 107 108 … 159 Next »
help with VB2005

 
  • 0 Vote(s) - 0 Average
help with VB2005
Azimuth
Offline

Member

Posts: 225
Threads: 47
Joined: Oct 2006
#1
2007-01-16, 07:35 AM
I know this is an odd thing to post in here (and I hope sub or anyone else doesn't kick me for it)
Believe me, I have tried posting in many forums with either no replies or silly responses such as "code in linux not windows"
anyway, this forum has the nicest people, and I'm sure many avid coders.
so please, if you can, help Smile

I have been trying to understand listview controls in VB2005 and can't seem to grasp the syntax.

Imagine a PO application needs to list rows with: Qty | Object | Description | price
on the form.
I have been able to populate the listview, however, I need to allow users to either remove rows or edit them. This is where I have been unable to create valid syntax.

It would be a great help if anyone is able to help me.
[SIZE="1"]SuperMicro PDSME+ Core2Duo 2.40GHz 6.0GB Ram | HD Homerun | (4) NMT | GB-PVR v1.5.21 | Windows 7 Enterprise x64[/SIZE]
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#2
2007-01-16, 07:50 AM
you should be able to just treat the columns like any other collections and do what you like with them.

listview1.items.Remove (and removeAt)

then for editing just set a listitem = listview.items[int index]

then you edit the subitems collection.

that's what i can remember....

Hope it helps.
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#3
2007-01-16, 07:59 AM
this may help....
http://www.dreamincode.net/forums/showtopic20503.htm
Azimuth
Offline

Member

Posts: 225
Threads: 47
Joined: Oct 2006
#4
2007-01-16, 09:02 AM
Private Sub lvProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvProducts.SelectedIndexChanged


tbQty.Text = lvProducts.Items(0).SubItems(1).Text.ToString


End Sub

works for row 0 but I can't leave out the .Items(0) from that line.
I know it has to be something simple, I guess it's just my perspective.
[SIZE="1"]SuperMicro PDSME+ Core2Duo 2.40GHz 6.0GB Ram | HD Homerun | (4) NMT | GB-PVR v1.5.21 | Windows 7 Enterprise x64[/SIZE]
hammerstein06
Offline

Junior Member

Posts: 10
Threads: 1
Joined: Jan 2007
#5
2007-01-16, 09:40 AM
A listview control is a collection of listview items.

Each item is a collection of fields. So, in your example above, Qty, Object, Description, Price.

To remove items, I would do something like;

if (listView1.SelectedIndices.Count > 0)
{
foreach (ListViewItem CurrentItem in listView1.SelectedItems)
{
listView1.Items.Remove( CurrentItem );
}
}

That's C#, I know, but you should be able to figure out what you need from that.

To edit items, I would start with making sure they only have one row selected, then move the item out into a temporary item, declared globally, and then have a button press;

private void button4_Click( object sender, EventArgs e )
{
if (listView1.SelectedIndices.Count == 0 || listView1.SelectedIndices.Count > 1)
{
MessageBox.Show( "You can only edit a single item" );
}
else
{
EditingItem = listView1.SelectedItems[0];

textBox2.Text = EditingItem.SubItems[0].Text;
textBox3.Text = EditingItem.SubItems[1].Text;
}
}

When they've edited what they want;

private void button5_Click( object sender, EventArgs e )
{
EditingItem.SubItems[0].Text = textBox2.Text;
EditingItem.SubItems[1].Text = textBox3.Text;
}

will update the item in the list, because EditingItem is a pointer to the actual listview item.

I'm sure this is one of many ways to go at this, but it should allow you to figure it out.
Azimuth
Offline

Member

Posts: 225
Threads: 47
Joined: Oct 2006
#6
2007-01-16, 09:57 AM
is there a good way to make listView1.SelectedItems[0] (the row number) dynamic?
or am i not grasping the concept?
[SIZE="1"]SuperMicro PDSME+ Core2Duo 2.40GHz 6.0GB Ram | HD Homerun | (4) NMT | GB-PVR v1.5.21 | Windows 7 Enterprise x64[/SIZE]
hammerstein06
Offline

Junior Member

Posts: 10
Threads: 1
Joined: Jan 2007
#7
2007-01-16, 10:02 AM
I don't think I quite understand what you mean by dynamic?

If you're meaning, can you access the array of items by name rather than index then no(i.e listView1.Items["MyItem"]), I don't think that's possible with the stock listview.

What is your application trying to do? I might be able to offer more assistance (or even another solution for you)
Azimuth
Offline

Member

Posts: 225
Threads: 47
Joined: Oct 2006
#8
2007-01-16, 10:11 AM
oops, Now i see.. I am getting an error if I try to edit a second row.
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
I thought it happened if I selected anything other than row 0
I guess I somehow need to reset ".selectedItems" after the first selection
[SIZE="1"]SuperMicro PDSME+ Core2Duo 2.40GHz 6.0GB Ram | HD Homerun | (4) NMT | GB-PVR v1.5.21 | Windows 7 Enterprise x64[/SIZE]
hammerstein06
Offline

Junior Member

Posts: 10
Threads: 1
Joined: Jan 2007
#9
2007-01-16, 10:14 AM (This post was last modified: 2007-01-16, 10:24 AM by hammerstein06.)
SelectedItems is a ListViewItemCollection, to find out how many items you have selected, you would check, listView1.SelectedItems.Count

Can you describe what you're trying to acheive, or are you just trying to learn how to use the listview?

Have a look at the attached program
[SIZE="1"]Pentium D 3.0ghz - 2048gb PC2-4200 - Radeon X1600XT - Hauppauge PVR-150 - 80gb Boot, 400gb Work, 160gb Media - XP Pro SP2[/SIZE]
Azimuth
Offline

Member

Posts: 225
Threads: 47
Joined: Oct 2006
#10
2007-01-16, 10:23 AM
I am writing a Purchase Order application and attempting to use the listview control to create the list of items to be ordered.
I'm not particularly tied to the ListView control, but i figured it was a good way to store the entered data before posting it to the database along with the rest of the form data.

so conceivably the user would add multiple products to the order and could update the quantity or remove products from the purchase order.
[SIZE="1"]SuperMicro PDSME+ Core2Duo 2.40GHz 6.0GB Ram | HD Homerun | (4) NMT | GB-PVR v1.5.21 | Windows 7 Enterprise x64[/SIZE]
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): 1 2 Next »


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode