DataGrid programming

Hi All

I have got problem to datagrid in C#

I have created a datagrid and its datasource is a table having quentity, price and total. So what need is when i enter price and total it should be calculted the total . And later i edit the price or quantity total should be reclaculated. I know that i should wite code in a particular event in the datagrid. I worote some code for cellcahnged event. But it is not working it gives the stack overflow error.

Can anyone have experienced about similar task please give me a hint for me to continue the work

Best Regards

Niroshan



Answer this question

DataGrid programming

  • josh1234

    can't u give some examle for this
  • Jason N

    can anyone give me a sample code for this work
  • Karsten Burger

    hi

    you can check column data type

    sai



  • yumin

    DataSet ds;

    public Form1()

    {

    InitializeComponent();

    ds = new DataSet();

    ds.Tables.Add(new DataTable("Test"));

    ds.Tables["Test"].Columns.Add ( new DataColumn("Quantity",System.Type.GetType("System.Int32")));

    ds.Tables["Test"].Columns.Add(new DataColumn("Cost", System.Type.GetType("System.Decimal")));

    ds.Tables["Test"].Columns.Add ( new DataColumn("Total", System.Type.GetType("System.Decimal")));

    dataGridView1.DataSource = ds.Tables["Test"];

    }

    private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)

    {

    if (dataGridView1["Quantity", e.RowIndex].Value != System.DBNull.Value && dataGridView1["Cost", e.RowIndex].Value != System.DBNull.Value)

    {

    int i = Convert.ToInt32(dataGridView1["Quantity", e.RowIndex].Value.ToString());

    decimal j = Convert.ToDecimal( dataGridView1["Cost", e.RowIndex].Value.ToString());

    dataGridView1["Total", e.RowIndex].Value = i * j;

    }

    }

    Hope this is what you are looking for............



  • DataGrid programming