473,506 Members | 13,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

list view question

See Code:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim oListView As New ListView
Dim oItem As ListViewItem
Dim cnt As Integer
Dim msg As String
Me.Controls.Add(oListView)
oListView.Dock = DockStyle.Fill
oListView.Columns.Add("Line #", 80, HorizontalAlignment.Right)
oListView.View = View.Details
For cnt = 1 To 100
msg = "LINE #: " & CStr(cnt)
oItem = oListView.Items.Add(msg, 0)
If cnt = 23 Then
oListView.Items(22).Selected = True
oListView.EnsureVisible(22)
End If
Next
End Sub

How come when I run the code, line 23 is selected (like I want), but if
I hit the down arrow, the selection moves to item 2 and NOT item 24. I
want it to move to item 24.

Can someone PLEASE help me.

Thanks.
Darin

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
3 1297
Hi Darin

Include the following line as well:

oListView.Items(22).Focused = True

HTH

Charles
"Darin" <darin_nospam@nospamever> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
See Code:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim oListView As New ListView
Dim oItem As ListViewItem
Dim cnt As Integer
Dim msg As String
Me.Controls.Add(oListView)
oListView.Dock = DockStyle.Fill
oListView.Columns.Add("Line #", 80, HorizontalAlignment.Right)
oListView.View = View.Details
For cnt = 1 To 100
msg = "LINE #: " & CStr(cnt)
oItem = oListView.Items.Add(msg, 0)
If cnt = 23 Then
oListView.Items(22).Selected = True
oListView.EnsureVisible(22)
End If
Next
End Sub

How come when I run the code, line 23 is selected (like I want), but if
I hit the down arrow, the selection moves to item 2 and NOT item 24. I
want it to move to item 24.

Can someone PLEASE help me.

Thanks.
Darin

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #2
If you checkout the selected indices property using your current code
you'll probably find that you have 2 items in the collection.
(Item 0 ) selected by default and item 22 selected by your code. When you
hit the down arrow the underlying UI nav for the list box
chooses the first item as the point of origin and then moves from it to the
next (item 2).

You'd be better off appending these items as an array and using BeginUpdte
& . EndUpdate (much faster and cleaner etc). But in just going with your
flow i'd rewrite like this an see what happens:

With oListView
For cnt = 1 To 100
msg = "LINE #: " & CStr(cnt)
oItem = .Items.Add(msg, 0)
Next

.SelectedItems.Clear
.Items(22).Selected = True
.EnsureVisible(22)
End With

Crap code but it should work.

Richard

I think you'd be better of using the selectedindex property.
"Darin" <darin_nospam@nospamever> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
See Code:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim oListView As New ListView
Dim oItem As ListViewItem
Dim cnt As Integer
Dim msg As String
Me.Controls.Add(oListView)
oListView.Dock = DockStyle.Fill
oListView.Columns.Add("Line #", 80, HorizontalAlignment.Right)
oListView.View = View.Details
For cnt = 1 To 100
msg = "LINE #: " & CStr(cnt)
oItem = oListView.Items.Add(msg, 0)
If cnt = 23 Then
oListView.Items(22).Selected = True
oListView.EnsureVisible(22)
End If
Next
End Sub

How come when I run the code, line 23 is selected (like I want), but if
I hit the down arrow, the selection moves to item 2 and NOT item 24. I
want it to move to item 24.

Can someone PLEASE help me.

Thanks.
Darin

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #3
Thanks -that worked

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #4

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

Similar topics

8
1857
by: Guy Hocking | last post by:
Hi there, I am having a few problems compiling a list box that is conditional on what is selected in another list box. What i need is a List box (lstArea) that displays one thing when the List...
5
3608
by: Xah Lee | last post by:
suppose i'm going to have a data structure like this: , , , , .... ] should i use (width,height) or ?
19
13542
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e.,...
5
2274
by: Praveen R | last post by:
Hi ! I am using a List view control to populate data onto. On the click event of the list view control, i need to find out whether the area clicked has any information of has no information. I...
0
3214
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
90
10699
by: Christoph Zwerschke | last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist only since Python 2.4. Anyway, I was thinking about whether it would be possible and desirable to change the old behavior in...
15
25715
by: Andrew Brampton | last post by:
Hi, This may sound a odd question, but I wanted to know how you return a list of data from a function. These are some of the ways I know how, and I was wondering which method you normally use....
2
1704
by: Kaur | last post by:
Hi, I have a form Form1 that displays surveys. This form has a subform1 which displays questions related to a particular survey. This subform has a subsubform which displays subquestions for a...
0
1139
by: anna_parkins7 | last post by:
Hi Quick question, that will point me in the right direction. I have 2 user controls on a page, both called List.ascx but obviously in 2 different namespaces and 2 different tags.. however I get...
1
1487
by: Jeff Williams | last post by:
With a list view is it possible and if so how to turn off the search function. What I mean is if you are in a list view and start typing it will search the first column to match or close match a...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.