473,225 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

How to: retrieve list of selected items in listview with virtual mode on

Since no one else knew how to do this I sat here all morning experimenting
with this and this is what I came up with... Its an example of how to get a
list of items back from a virtual mode list view in .NET 2.0 with multiple
selection turned on... since the .NET documentation is EXTREAML vague on how
to do this and offers no clue on what the virtual mode events do or how to
use them... just thought this might help someone else out...


Public Class Form1

''' <summary>

''' Retrieve thousands of rows of data from database server to fill
dataset to populate list view

''' </summary>

''' <remarks></remarks>

Dim db As New SqlClient.SqlConnection("Data Source=sqlserver;Initial
Catalog=development;Integrated Security=SSPI;Min Pool Size=5;Max Pool
Size=60;Connect Timeout=600;")

Dim da As New
SqlClient.SqlDataAdapter("BENESP_GetJournalEntries ForUser", db)

Dim ds As New DataSet

Dim aItems(0) As ListViewItem

''' <summary>

''' Moves data from data set into an array of list view items (speeds
things up when you preprocess the

''' data set into list view items so you dont have to make them on the
fly when retrieveing virtual items

''' </summary>

''' <remarks></remarks>
Private Sub LoadData()
' Process data items into list view items here and put into array for
easy retrieval
End Sub

''' <summary>

''' Pulls the virtual item out of the list as it is needed to display
on the screen from the

''' array of preprocessed list view items from the initially loaded
data set

''' </summary>

''' <param name="sender"></param>

''' <param name="e"></param>

''' <remarks></remarks>

Private Sub ListView1_RetrieveVirtualItem(ByVal sender As Object,
ByVal e As System.Windows.Forms.RetrieveVirtualItemEventArgs) Handles
ListView1.RetrieveVirtualItem

e.Item = aItems(e.ItemIndex)

End Sub

''' <summary>

''' This happens when a selection is reset to no items selected, like
when a user clicks off a selection

''' </summary>

''' <param name="sender"></param>

''' <param name="e"></param>

''' <remarks></remarks>

Private Sub ListView1_VirtualItemsSelectionRangeChanged(ByVal sender
As Object, ByVal e As
System.Windows.Forms.ListViewVirtualItemsSelection RangeChangedEventArgs)
Handles ListView1.VirtualItemsSelectionRangeChanged

Debug.WriteLine(String.Format("{3}: Start {0}, End {1}, IsSelected
{2}", e.StartIndex, e.EndIndex, e.IsSelected, Now.ToLongTimeString))

Me.ListBox1.Items.Clear()

End Sub

''' <summary>

''' This happens when a user selects items or multiple selects items
or deselects one of the multi selected items

''' This does not fire though if you have an item selected then click
off it or have multiple items selected then

''' click off them... the virutal selection range change happens at
that point and need to reset your selected

''' items list at that point

''' </summary>

''' <param name="sender"></param>

''' <param name="e"></param>

''' <remarks></remarks>

Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object,
ByVal e As System.Windows.Forms.ListViewItemSelectionChangedE ventArgs)
Handles ListView1.ItemSelectionChanged

Debug.WriteLine(String.Format("Item Changed: {0}, Is selected: {1}",
e.ItemIndex, e.IsSelected))

If e.IsSelected = True Then

Me.ListBox1.Items.Add(CStr(e.ItemIndex))

Else

Me.ListBox1.Items.Remove(CStr(e.ItemIndex))

End If

End Sub

End Class


Nov 21 '05 #1
0 7501

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jasper Recto | last post by:
I have a little program that has several list boxes. If I click on an item in one list box, it highlights the selection. If I click on another item in a DIFFERENT list box, it highlights that...
7
by: Jax | last post by:
I understand that it's supposed to contain text, usually. But as it takes an object can you be really cheeky and put a very complex object in there instead? Would any problems come from doing...
2
by: Peter | last post by:
Hello! Please, could anyone tell, is it possible to set multiple items to be selected in list control in the code? For example when the web form is loaded three items of 5 are selected in list...
6
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the...
5
by: Darin | last post by:
I have a listview box in detail view with 100+ items. I can select the 50th item by lstdetail.items(49).selected=true. But, when I do that the item is selected, but the listview box hasn't scrolled...
7
by: Flavio | last post by:
Hi, I have a QListview widget that allows me to store a bunch of strings in it. This strings can be visualized, sorted, selected, etc. My Problem is that I cant find a way to get the user...
0
by: Smokey Grindle | last post by:
Say I do the following in a virtual list box ctrl click one row then ctrl click another row... ok the VirtualItemsSelectionRangeChanged event fires with start index of 2 and end index of 10... ...
3
by: grzegorz.gazda | last post by:
Hi all Is there any limit of images which can be added to a image list. I have a problem with this control. I added an image list in design mode and I am adding images using code. Then I want to...
1
by: divya | last post by:
Hello, I used the below code to move selected items between two listboxes Left and Right:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %> ...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.