Results 1 to 3 of 3

Thread: [RESOLVED] listView issue

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    45

    Resolved [RESOLVED] listView issue

    Hello. I'm trying to do some basic work with reading data from a listView for modification. I don't understand the exception.

    Code:
    void listView3_SelectedIndexChanged(object sender, EventArgs e)
    {
       pg3_pnl1_txtEmpID.Text = listView3.SelectedItems[0].SubItems[0].Text;
       pg3_pnl1_txtEmpName.Text = listView3.SelectedItems[0].SubItems[1].Text;
       pg3_pnl1_txtSupName.Text = listView3.SelectedItems[0].SubItems[2].Text;
       pg3_pnl1_txtTimesPicked.Text = listView3.SelectedItems[0].SubItems[3].Text;
    }
    My listView has 4 columns. As you can see, when the user selects a row, i just want the 4 values to be copied into 4 different text boxes.

    This is the problem. It works fine the first time I select a row--the data copies over to the text boxes without any error. But when i try to select a different row after that, it throws this exception, but allows me to hit 'continue' and it still copies the data over.

    Code:
    System.ArgumentOutOfRangeException was unhandled
      Message="InvalidArgument=Value of '0' is not valid for 'index'.\r\nParameter name: index"
      Source="System.Windows.Forms"
      ParamName="index"
      StackTrace:
           at System.Windows.Forms.ListView.SelectedListViewItemCollection.get_Item(Int32 index)
           at SafetyStickers.MainForm.listView3_SelectedIndexChanged(Object sender, EventArgs e) in C:\Documents and Settings\a1tn5zz\Desktop\Projects\SafetyStickers\SafetyStickers\MainForm.Designer.cs:line 1244
           at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)


    In addition. I want to be able to update these values in the database. But, attempting to perform an update throws an exception as well.

    Code:
            void pg3_pnl1_btnModify_Click(object sender, EventArgs e)
            {
                string EmpID = pg3_pnl1_txtEmpID.Text;
                string EmpName = pg3_pnl1_txtEmpName.Text;
                string SupName = pg3_pnl1_txtSupName.Text;
                int TimesPicked = int.Parse(pg3_pnl1_txtTimesPicked.Text);
    
                string sql = "UPDATE EmployeeList SET Person_Identifier=\"" + EmpID + "\", Employee_Name=\"" + EmpName + "\", Supervisor_Name=\"" + SupName + "\", TimedPicked=" + TimesPicked + " WHERE Person_Identifier=\"" + listView3.SelectedItems[0].SubItems[0].Text + "\"";
    
                OleDbCommand cmd = new OleDbCommand(sql);
                cmd.Connection = this.conn;
                cmd.ExecuteNonQuery();				// Perform update operation
                cmd.Dispose();	
            }
    TimesPicked is a Number in the database where as the others are Strings. Here is the exception for that.

    Code:
    System.Data.OleDb.OleDbException was unhandled
      Message="No value given for one or more required parameters."
      Source="Microsoft JET Database Engine"
      ErrorCode=-2147217904
      StackTrace:
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
           at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
           at SafetyStickers.MainForm.pg3_pnl1_btnModify_Click(Object sender, EventArgs e) in C:\Documents and Settings\a1tn5zz\Desktop\Projects\SafetyStickers\SafetyStickers\MainForm.Designer.cs:line 1269
           at System.Windows.Forms.Control.OnClick(EventArgs e)

    Thanks for any help.
    Last edited by Hack; Jan 9th, 2009 at 08:21 AM. Reason: Added RESOLVED to thread title and green resolve checkmark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width