Jump to content
xisto Community
Sign in to follow this  
vhortex

VB.NET: Problem With Listview Controls

Recommended Posts

Hello, I am kinda new to Vb.net and I need some help regarding listview.I want to add a certain value at a certain location for a listview. Like adding a new row at the current selected area.What the program do as of now was to add new rows at location 0.can anyone help me.. thanks..

Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

Hello, I am kinda new to Vb.net and I need some help regarding listview.

 

I want to add a certain value at a certain location for a listview. Like adding a new row at the current selected area.

 

What the program do as of now was to add new rows at location 0.

 

can anyone help me..

 

thanks..

1064329505[/snapback]


What do you mean by new row at the currently selected area ? Can you be a little more clear on that ?

 

ListView object won't add rows at location 0, as far as I know. Instead it would put it at the bottom.

 

If you mean that you want to add a row ABOVE or BELOW a single or a set of items in the listview, then you can take the following approach:

 

For a ListView you can set it's property MultiSelect to true. If so, an user might select a single row or multiple rows at a time. If set to false a user ca select only a SINGLE line.

 

Say, I want to insert a row below a selected row.

There's a method called SelectedIndices() under ListView class which returns an array containing the Index of the selected items in the list. The index of the first item is ZERO.

 

Now in case MultiSelect is set to false - SelectedIndices will return only a single row, but when MultiSelect is true, this will return an array.

 

If false, we can get the selected row (lets say, Max) by simply looking for it's index in the SelectedIndices() array's position ZERO - why we can be sure that this item will be in position ZERO is - that this array will containing ONLY ONE item, based on MultiSelect to be false.

So two cases:

 

Case 1: MultiSelect = false

Dim Max as Integer = lsvReceipts.SelectedIndices.Item (0)

OR,

 

Case 2: MultiSelect = true

If not, from that array you have to determine the highest index of the SelectedItems, to know which position you've to insert this new value.

Lets use a short example with this list of receipts ( lsvReceipts ):

            'We start by creating a variable called Max and store the first index in            'SelectedIndices Array.            Dim Max As Integer = lsvReceipts.SelectedIndices.Item(0)            'We go through the SelectedIndices Array and find the highest index stored in it.            'We loop through 0 to SelectedIndices.Count - 1, as we're counting from '0' .            For Counter = 0 To lsvReceipts.SelectedIndices.Count - 1                'Check with the item in each position - see if it's greater than Max                If Max < lsvReceipts.SelectedIndices.Item(Counter) Then                    'Set Max equal to it                    Max = lsvReceipts.SelectedIndices.Item(Counter)                End If            Next            'Now we know the Index of the Last Selected Item ( stored in Max )

So armed with the last selected item's position, we ADD a '1' to it, since what we want to insert, goes at a position below it. So

'Increase Max by '1'Max += 1

Now, simply issue an insert statement:

'Insert new item at that position.lsvReceipts.Items.Insert ( Max, "New Item" )

There you go... ;)

Share this post


Link to post
Share on other sites

Oh, I am sorry, this should go to the VB.net portion.

I am going to edit the post and topic until I found out someone have mess with the proxy server and block the word listview.

here is the more detailed problem.


I have a listview in vb.net. The purpose of the listview is to display data to the screen which is fetch from a mySQL database.

The listview needs an Insert function where the purpose of the insert is to add a new row in the listview at the exact location where the user clicks [selected item] and move the rows displayed 1 line below down by 1 row.

this is a crude example of the code that I am facing

LVI = uiListViewSData.Items(0)        indx = uiListViewSData.SelectedItems(0).Index         uiListViewSData.Items().Insert((indx + 1), "")

I guess that the problem is with VB.net, for some reason the same code now runs.

There is no modification whatsoever..

Can you kindly move this topic to vb.net section for there are more people who may need this answer.

Share this post


Link to post
Share on other sites

this is a crude example of the code that I am facing

LVI = uiListViewSData.Items(0)        indx = uiListViewSData.SelectedItems(0).Index         uiListViewSData.Items().Insert((indx + 1), "")

I guess that the problem is with VB.net, for some reason the same code now runs.

 

There is no modification whatsoever..

1064329645[/snapback]


First - read the first post I made on this thread.

 

Now, your command, indx = uiListViewSData.SelectedItems(0).Index - fetches you the index of SelectedItems(0) - which should be okay, but sometimes I've had problems with the SelectedItems method - so I resort to using SelectedIndices() instead. See for yourself in this case, uiListViewSData.SelectedItems(0).Index is returning '0' as an index to your SelectedItems(0). Hence, quite obviously, your data WILL get added to the ZERO-eth position.

 

Since you're choosing just one row at a time, set MultiSelect of ListView to false and then use,

indx = uiListViewSData.SelectedIndices(0)

to fetch the selected row correctly.

 

Insertion is exactly what you're come up with:

uiListViewSData.Items().Insert((indx + 1), "New Item....")

Share this post


Link to post
Share on other sites

I think you have mis-interpreted my post, anway the index stuff returns non zero because the requirements is that you must click the row first.. I used to use msgbox() to see what the returned value was.---it is working now without any modification..my next question is if you still have time..are there any method to make the listview editable by clicking a certain column and row in the listview?---about the indices i have coded a newer one with the indices that you have recommended but i have not yet rebuild the project .

Share this post


Link to post
Share on other sites

my next question is if you still have time..

 

are there any method to make the listview editable by clicking a certain column and row in the listview?

 

---

1064329653[/snapback]


Hehe.. I've used so much of listview during past two months, I could write a walkthrough blindfolder...

 

Anyways, basically there are 2 controls in VS.NET that can produce similar LIST outputs:

1. ListView

2. Datagrid

 

Both have advantages and disadvantages. Datagrid is way more complex but immensely powerful. ListView far easier (and works faster) - but limited in features.

 

With DataGrid, you can easily achieve what you want to do - EDIT any particular COLUMN in a ROW.

 

With ListView, unfortunately - you can edit ONLY the FIRST column of each ROW - which itself is an ITEM (which you add to the ListView)... all other columns associated with this ITEM are SUBITEMS, which are NON-EDITABLE. Anyways, to go ahead and edit only the first item, you've to set the ListView property called LabelEdit to TRUE.

 

In case you want to do the same with DataGrid (but be able to edit ALL) - let me know. I can help you out there too.

 

Regards,

m^e

Share this post


Link to post
Share on other sites
LISTVIEW PROBLEM.VB.NET: Problem With Listview Controls

 Hi. I have a problem regarding listview control in asp.Net and vb.Net. I'm developing a web based application wherein the user will search for a topic and the search results will be displayed and bind  in a listview. There's a link in a listview where users can click to view a file.

I want to get the selected value of each item in a listview after the user click the link.

Anyone knows how to do it?

Thanks..

You can email me here: norbs_27@yahoo.Com

Thanks a lot and godbless!

-reply by Norbs

 

Share this post


Link to post
Share on other sites
wpf listview backcolor as tranparentVB.NET: Problem With Listview Controls

hi all,

I have a problem to set the listview backcolor as transparent. I already tried but still cannot work. I use vb.Net languange WPF. Anyone can help me?? Thanks in advance.

You can reply here or to my email - choc.Creezy@gmail.Com

-reply by ct kd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.