Problem with Listview Controls in VB.NET
Hello everyone i am very much new to VB.Net programming language. I am having a problem with the listview control in VB.NET. Actually i want to add a certain value at a certain location for a listview in VB.net. For example consider adding a new row at the currently selected area. The program which i have does the addition of new rows but at the location '0' . Kindly give a suitable solution.
Re: Problem with Listview Controls in VB.NET
It will be better to implement a solution to your problem if you provide some more information on this problem. Be more clear , What you actually mean by saying new row at the currently selected area. Please try to present a clear picture of your problem. As far as i am aware of the VB.NET the Listview object adds a row at the bottom instead of adding a row at the location 0.
Re: Problem with Listview Controls in VB.NET
Assuming that you want to add a row below or above a single or a set of items or a multiple rows at a time. you can take the following approach to achieve it.
for inserting a row below a selected row. You will have to make use of the method SelectedIndices() under the list view class which will return an array containing the Index of the selected items in the list. The index of the first item is 0.
and your code will somewhat look like
Dim Max as Integer = lsvname.SelectedIndices.Item (0)
Re: Problem with Listview Controls in VB.NET
Thanks for the replies As one of you have asked to some more detail regarding the problem so i will be providing it. Also the solution implemented by opaper was really a good initiative but that too could give me the desired output. So i am expecting some other solution. Lets me make the problem somewhat more clearer the main objective of the listview is to display data to the screen which is fetch from a mySQL database.
Hear is a part of code
Code:
lsv1 = uiListViewSData.Items(0)
indx = uiListViewSData.SelectedItems(0).Index
uiListViewSData.Items().Insert((indx + 1), "")
Re: Problem with Listview Controls in VB.NET
I will suggest another approach to achieve this you can get the selected row by simply looking it's index in the SelectedIndices() array's position ZERO. why are you very much sure that this item will be in position ZERO is. Since this array will contain only one item because you are keeping multiselect FALSE. Use the code mentioned below.
Code:
Dim Max As Integer = lsvReceipts.SelectedIndices.Item(0)
For Counter = 0 To lsvReceipts.SelectedIndices.Count - 1
If Max < lsvReceipts.SelectedIndices.Item(Counter) Then
Max = lsvReceipts.SelectedIndices.Item(Counter)
End If
Re: Problem with Listview Controls in VB.NET
It seems as your Listview requires another insert function inorder to add a new row within the listview and at the desired location where the user clicks and move the rows displayed 1 line below down by 1 row.
Following is the code please refer it.
Lstv = uiListViewSData.Items(0)
indx = uiListViewSData.SelectedItems(0).Index
uiListViewSData.Items().Insert((indx + 1), "")
Re: Problem with Listview Controls in VB.NET
Hey Guys,
Here is simplest one article on ListView control in vb.net, for more information please visit this the following url....
http://mindstick.com/Articles/5924b8...%20in%20VB.Net
:rofl_2: Thanks !!!