Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to generate all the data in gridview current row. But the condition is the when i put value id in datagrid view cell it automatic fill that row? (Just like put a barcode value in data grid view cell).

What I have tried:

C#
if (dataGridView1.Rows.Count>1)
{
    DataTable dt = new DataTable();
    //fetching the data form the item code or barcode
    //  MessageBox.Show(dataGridView1.Rows[0].Cells["calitem_name"].Value.ToString());
    dt = blsto.getallstockbyname((dataGridView1.CurrentRow.Cells["calbar_code"].Value).ToString());

    if (dt.Rows.Count > 0)
    {

        //get crt price
        DataTable dts = blcrt.getpricebycrtvalue(dt.Rows[0]["crt_value"].ToString());
        decimal crt_price = Convert.ToDecimal(dts.Rows[0]["crt_price"].ToString());

        //
        decimal weight = Convert.ToDecimal(dt.Rows[0]["weight"].ToString());
        int quantity = Convert.ToInt32(dt.Rows[0]["quantity"].ToString());
        decimal making_charge = Convert.ToDecimal(dt.Rows[0]["labour_charge"].ToString());
        decimal stone_price = Convert.ToDecimal(dt.Rows[0]["stone_charge"].ToString());
        decimal margin_price = Convert.ToDecimal(dt.Rows[0]["margin_price"].ToString());
        decimal past_sell_price = Convert.ToDecimal(dt.Rows[0]["sell_price"].ToString());
        decimal todaysellprice = Convert.ToDecimal((weight * crt_price) + margin_price + stone_charge + making_charge);



        dataGridView1.CurrentRow.Cells["calitem_name"].Value = dt.Rows[0]["item_name"].ToString();
        dataGridView1.CurrentRow.Cells["calweight"].Value = dt.Rows[0]["weight"].ToString();
        dataGridView1.CurrentRow.Cells["calqty"].Value = dt.Rows[0]["quantity"].ToString();
        dataGridView1.CurrentRow.Cells["calrate"].Value = dt.Rows[0]["sell_price"].ToString();
        dataGridView1.CurrentRow.Cells["calcrt"].Value = dt.Rows[0]["crt_value"].ToString();
        dataGridView1.CurrentRow.Cells["calstoneprice"].Value = dt.Rows[0]["stone_charge"].ToString();
        dataGridView1.CurrentRow.Cells["caltotal"].Value = todaysellprice;


    }

    else
    {
        lbl_barcode.Text = "Set Barcode Again, Can't find Product";
    }

    decimal result = 0;
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        result += Convert.ToDecimal(row.Cells["caltotal"].Value);
    }
    txtsubtotal.Text = result.ToString();

}
Posted
Updated 18-Mar-16 0:54am
v2
Comments
VR Karthikeyan 18-Mar-16 6:48am    
Do you got any error while running the above code? What's the problem you are facing? pls elaborate it.
Ank_ush 18-Mar-16 6:54am    
What problem you are facing???
Member 12242717 20-Mar-16 2:04am    
when i enter a barcode in data grid view cell it automatically fill all current row cell.

1 solution

Change code like this,
C#
dataGridView1.Rows[rowindex].Cells["column_name or column_index"].Value = your_value;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900