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
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