ullas K

ullas K

  • 0
  • 55
  • 0

Changing the Column value of a bound datagridview

Feb 9 2013 7:12 AM
Hi,
    I have a datagridview with columns Member No, Member Name ,Address,Phone and Membership_Status.membership_Status column is of type integer(Column values will be 1,2,3,4).What i need is when the datagridview is populated i should replace the integer values in column membership_Status ,ie if value is "1" then the column should show "Guardian".If "2" the Status column should show "Life" and so on. but i am getting error;
System.Exception:Guardian is not a valid value for int32---->System.FormatException:Input string was not in a correct format
How can i correct this formatexception.My code is shown below;

LibraryLib.Library obj = new LibraryLib.Library();
            DataTable dt;
            DataGridViewRow dgr;
            int i ;
            dt = obj.select("select member_no,mname,address,phone,membership_status from Member_master");
            dataGridView1.DataSource = dt;
            dataGridView1.Refresh();
            int status;
            for (i = 0; i < dataGridView1.Rows.Count; i++)
            {
                dgr = dataGridView1.Rows[i];
                status = int.Parse(dgr.Cells[4].Value.ToString());
               

                switch (status)
                {
                    case 1:

                        dgr.Cells[4].Value = "Guardian";
                        break;
                   case 2:

                        dgr.Cells[4].Value = "Life";
                        break;
                  case 3:

                        dgr.Cells[4].Value = "Active";
                        break;
               }
How can i acheive this.Pls give me the code to do this
Thanks in advance


Answers (4)