•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 391,709 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,403 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 469 | Replies: 7 | Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 32
Reputation:
Rep Power: 1
Solved Threads: 0
Hi
i have a listview which is populated with a number of 'Appointments' and when selected this fills a number of lables with information.
now on the first click it works fine and everything gets populated but when a different row is selected i get an error.
the code im using is
the error is appearing on the row 'lblCustID.Text = selection.SubItems(2).Text '
with the error message
' InvalidArgument=Value of '2' is not valid for 'index'. Parameter name: index '
i wondered if anyone could help
i have a listview which is populated with a number of 'Appointments' and when selected this fills a number of lables with information.
now on the first click it works fine and everything gets populated but when a different row is selected i get an error.
the code im using is
Dim selection As ListViewItem = lstDays.GetItemAt(e.X, e.Y)
If (selection IsNot Nothing) Then
lblCustID.Text = selection.SubItems(2).Text
FillCustData(selection.SubItems(2).Text)
Else
MsgBox("There is no current appointment set for " & selection.SubItems(2).Text & " Would you like to make one?")
Return
End If
the error is appearing on the row 'lblCustID.Text = selection.SubItems(2).Text '
with the error message
' InvalidArgument=Value of '2' is not valid for 'index'. Parameter name: index '
i wondered if anyone could help
•
•
Join Date: Feb 2008
Location: Sivakasi, Tamilnadu, India
Posts: 366
Reputation:
Rep Power: 1
Solved Threads: 61
To select ListItems you can use ListView1.SelectedItems. This is a collection of Selected List Items. You can refer first selected item as ListView1.SelectedItems(0)
if ListView1.SelectedItems.Count > 0 then Dim selection As ListViewItem = ListView1.SelectedItems(0) ' Your Selected code End If
Last edited by selvaganapathy : Jun 25th, 2008 at 12:12 pm.
KSG
•
•
Join Date: Apr 2008
Posts: 32
Reputation:
Rep Power: 1
Solved Threads: 0
many thanks for your response
i have now amended my code to:
If lstDays.SelectedItems.Count > 0 Then
Dim selection As ListViewItem = lstDays.SelectedItems(0)
If lstDays.SelectedItems(0).SubItems(1).Text = "" Then
MsgBox("no appointment set")
Else
lbltest.Text = lstDays.SelectedItems(0).SubItems(1).Text
End If
End If
but im still getting an error when i click a row that has now value in column 2.
Because column one will always contain a value (Time) = i am checking that if column 2 is empty, then display message, else fill lable.
i have now amended my code to:
If lstDays.SelectedItems.Count > 0 Then
Dim selection As ListViewItem = lstDays.SelectedItems(0)
If lstDays.SelectedItems(0).SubItems(1).Text = "" Then
MsgBox("no appointment set")
Else
lbltest.Text = lstDays.SelectedItems(0).SubItems(1).Text
End If
End If
but im still getting an error when i click a row that has now value in column 2.
Because column one will always contain a value (Time) = i am checking that if column 2 is empty, then display message, else fill lable.
•
•
Join Date: Feb 2008
Location: Sivakasi, Tamilnadu, India
Posts: 366
Reputation:
Rep Power: 1
Solved Threads: 61
Hi
This may help u.
Draw a ListView Control (ListView1)
Try the Following code
This may help u.
Draw a ListView Control (ListView1)
Try the Following code
VB.NET Syntax (Toggle Plain Text)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim list As ListViewItem list = ListView1.Items.Add("One") list.SubItems.Add(" Sub Item 1") list = ListView1.Items.Add("Two") list.SubItems.Add(" Sub Item 2") ListView1.Columns.Add("Name") ListView1.Columns.Add("Address", 150) ListView1.View = Windows.Forms.View.Details ListView1.FullRowSelect = True End Sub Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click If ListView1.SelectedItems.Count > 0 Then Dim list As ListViewItem = ListView1.SelectedItems(0) MsgBox(list.Text & " " & list.SubItems(1).Text) End If End Sub
Last edited by selvaganapathy : Jun 26th, 2008 at 10:29 am.
KSG
•
•
Join Date: Feb 2008
Location: Sivakasi, Tamilnadu, India
Posts: 366
Reputation:
Rep Power: 1
Solved Threads: 61
I understand the problem, Try this
VB.NET Syntax (Toggle Plain Text)
Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click If ListView1.SelectedItems.Count > 0 Then Dim list As ListViewItem = ListView1.SelectedItems(0) 'Check whether subitems exists If list.SubItems.Count > 1 Then 'Here also check whether they are empty If list.SubItems(1).Text <> "" Then MsgBox(list.Text & " " & list.SubItems(1).Text) Else MsgBox("Incomplete") End If Else MsgBox("Incomplete") End If End If End Sub
Last edited by selvaganapathy : Jun 26th, 2008 at 10:42 pm.
KSG
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
Similar Threads
- listview row details (VB.NET)
- How to overcoming a .NET ListView CheckBoxes quirk (VB.NET)
- FlexGrid issue and error "Invalid Row value".... (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: where i can find system.data.sqlclient in visual stdudio 2003
- Next Thread: Problem in creating efficient Log file


Linear Mode