Ashok Kumar

Ashok Kumar

  • NA
  • 38
  • 45.9k

selecting record from listview getting error while showing in textboxes

Aug 3 2012 2:31 AM
Hi friends,
        i am working a small application which should display data in textbox when selected the listview , the problem i am getting when i apply leaves for same employee code with differnt leave type and when i am selecting the recorded added listview to show data in textboxes it getting error and displaying the data but when i close the application and open and again i select the recorded from listview the error will not come for the first time applying and selected record for first time only it will come. please some one help me.

the error is
it will show  'fromdate ' in a small box, first time when i select listview index record, when i added leaves for same employee code different leave type

when i use break point listapproval.Items[i].Selected == true it is showin false and after that it will show

the code is

  private void listapproval_SelectedIndexChanged(object sender, EventArgs e)
        {
             try
            {
                groupBox3.Visible = true;
                txtEmpCode.Enabled = false;
                btnSave.Enabled = false;
                btnDelete.Enabled = true;
              //  btnDelete.Enabled = true;
                string empcode = "";
                string empname = "";
                string leavetype = "";
                string fromdate = "";
                string todate = "";
                string description = "";
                string status = "";
              

               
                for (int i = 0; i < listapproval.Items.Count; i++)
                {
                    if (listapproval.Items[i].Selected == true)
                    {
                        empcode = listapproval.Items[i].SubItems[0].Text;
                        empname = listapproval.Items[i].SubItems[1].Text;
                        leavetype = listapproval.Items[i].SubItems[2].Text;
                        fromdate = listapproval.Items[i].SubItems[3].Text;
                        todate = listapproval.Items[i].SubItems[4].Text;
                        status = listapproval.Items[i].SubItems[5].Text;
                        string q1="select LeaveCode From LeaveMaster Where LeaveName='"+leavetype+"'" ;
                            DBCom.getData(q1);
                        if(DBCom.rdr.HasRows)
                        {
                            while(DBCom.rdr.Read())
                            {
                                 lc =DBCom.rdr["LeaveCode"].ToString();

                            }
                        }


Answers (2)