Note that there are some explanatory texts on larger screens.

plurals
  1. POSolution for this error "InvalidArgument=Value of '0' is not valid for 'index'."
    text
    copied!<p>The 'cause of error is when I trigger the event, I tried to disable it to prevent the error. But, upon enabling it again. When, the event is triggered the error would show up again.</p> <p>I Googled some solutions like checking if items exist in the ListView</p> <pre><code>If ListView2.Items.Count &gt; 0 Then </code></pre> <p>I also, found some code on handling the event. But, It seems to do nothing.</p> <pre><code>AddHandler ListView2.SelectedIndexChanged, AddressOf ListView2_SelectedIndexChanged </code></pre> <p>I thought removing the items will remove the error. But, It didn't work.</p> <p>Here is the code:</p> <pre><code>For i = ListView2.Items.Count - 1 To 0 Step -1 ListView2.Items.Remove(ListView2.Items(i)) Next i </code></pre> <p>Below are the full codes for the event:</p> <pre><code>Private Sub ListView2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView2.SelectedIndexChanged If ListView2.Items.Count &gt; 0 Then TransactionID.Text = ListView2.SelectedItems(0).Text Label6.Left -= 190 Label7.Left -= 190 GroupBox1.Left -= 190 ListView2.Left -= 190 Button2.Visible = True ListView1.Visible = True GroupBox2.Visible = True Label4.Visible = True Label5.Visible = True ListView2.Enabled = False AddHandler ListView2.SelectedIndexChanged, AddressOf ListView2_SelectedIndexChanged End If End Sub </code></pre> <p>I found out that the cause of the error is that I'm trying to select the ListView2 but, I no longer have access to it, there are no items in the Listview or I haven't selected it. It's just strange the I made sure the Listview has items and the Listview is enabled.</p> <p>So yeah... What could possibly the solution for this?</p> <p>EDIT: ADDED THE CODE FOR BINDING THE LISTVIEW</p> <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ComboBox1.Text = "" Then MsgBox("Please specify status of transaction!") ComboBox1.Focus() End If Dim conn As MySqlConnection conn = New MySqlConnection() Label6.Text = 0 time = dateTo.Text format = "yyyy-MM-dd" outTo = (time.ToString(format)) outTo = outTo &amp; " " &amp; "23:59:59" time = dateFrom.Text format = "yyyy-MM-dd" outFrom = (time.ToString(format)) outFrom = outFrom &amp; " " &amp; "00:00:00" conn.ConnectionString = "server=localhost;user id=root;password=zhakige;database=singin" Dim strSQL = "SELECT transaction_id, transaction_status, transaction_staffusername ,transaction_date, transaction_totalprice FROM `transaction` WHERE transaction_date BETWEEN '" &amp; outFrom &amp; "' AND '" &amp; outTo &amp; "' AND transaction_status = '" &amp; ComboBox1.Text &amp; "';" conn.Open() Dim cmd = New MySqlCommand(strSQL, conn) Dim dr = cmd.ExecuteReader() ListView2.Items.Clear() Do While dr.Read() a = (dr.Item("transaction_id").ToString()) b = (dr.Item("transaction_status").ToString()) c = (dr.Item("transaction_staffusername").ToString()) time = (dr.Item("transaction_date")) format = "yyyy-MM-dd" output = (time.ToString(format)) d = output e2 = (dr.Item("transaction_totalprice").ToString()) Dim lv As ListViewItem = ListView2.Items.Add(a) lv.SubItems.Add(b) lv.SubItems.Add(c) lv.SubItems.Add(d) lv.SubItems.Add(e2) Label6.Text += Val(e2) Loop If ListView2.Items.Count &lt;= 0 Then MsgBox("No record found for specified options") End If dr.Close() cmd.Dispose() conn.Close() End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload