Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListView

Status
Not open for further replies.

jnavarro

Programmer
Joined
Dec 1, 2003
Messages
89
Location
US
I currently have a listview, I would like the user to click on the listview and select the item they want to edit. I am able to display the information from the listview to the textbox once. However, when the user clicks on another item I receive an error "out of range". How would I display the data from the Listview to the textboxes?

List below is my code.
load the information. this works

'Add a column with width
lstvwTypical.View = View.Details
lstvwTypical.Clear()
lstvwTypical.Columns.Add("Day", 72, HorizontalAlignment.Center)
lstvwTypical.Columns.Add("Shift Start", 81, HorizontalAlignment.Center)
lstvwTypical.Columns.Add("Shift End", 81, HorizontalAlignment.Center)
lstvwTypical.Columns.Add("Lunch Out", 81, HorizontalAlignment.Center)
lstvwTypical.Columns.Add("Lunch In", 81, HorizontalAlignment.Center)

For Each drCurrent In dt.Rows
lstvwTypical.Items.Add(drCurrent("DOW").ToString)
lstvwTypical.Items(intRow).SubItems.Add(FormatDateTime(drCurrent("ShiftStart").ToString, DateFormat.LongTime))
lstvwTypical.Items(intRow).SubItems.Add(FormatDateTime(drCurrent("ShiftEnd").ToString, DateFormat.LongTime))
lstvwTypical.Items(intRow).SubItems.Add(FormatDateTime(drCurrent("LunchO").ToString, DateFormat.LongTime))
lstvwTypical.Items(intRow).SubItems.Add(FormatDateTime(drCurrent("LunchI").ToString, DateFormat.LongTime))
intRow += 1
Next
display the selecteditem to textbox

With lstvwTypical

txtDOW.Text = .SelectedItems.Item(0).Text
txtStart.Text = .SelectedItems.Item(0).SubItems(1).Text
txtEnd.Text = .SelectedItems.Item(0).SubItems(2).Text

End With


thanks in advance
 
I figure this out. I forgot that evertime you click the listview it will fire the event. This cause an error reading the information.

here is the fix

If (lstvwTypical.SelectedItems.IndexOf(lstvwTypical.FocusedItem) <> -1) Then
With lstvwTypical
txtDOW.Text = .FocusedItem.Text
txtStart.Text = .FocusedItem.SubItems(1).Text
txtEnd.Text = .FocusedItem.SubItems(2).Text
txtLunchO.Text = .FocusedItem.SubItems(3).Text
txtLunchI.Text = .FocusedItem.SubItems(4).Text
End With
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top