HI all i m making a project for a departmental store. In that I have to make a bill generation form in which i have taken a gridview for the products entry which have been purchased by the customer.
I have taken 5 columns in that gridview. ProdId,ProdName,Qty,Price and total. Now i want that the moment i enter the prodId and press tab ProdName and Price for that product should display in that row and the moment i fill the quantity purchased it should display Total(Price*Qty) the ColumnName Total.
Also I need an Extra Cell at The Bottom of the GridView for Grand Total Which should automatically adjust its value according to Sum of all totals.
Thanks in Advance

Recommended Answers

All 3 Replies

This is a sample using 4 columns id quantity unit price and a dynamically added column that caucates the total

for the grand total you have to add a text box at the bottom of the page and summarize all values in the column 3

DataGridViewTextBoxColumn TotalColumn;
    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'productsDataSet.Prod' table. You can move, or remove it, as needed.
        this.prodTableAdapter.Fill(this.productsDataSet.Prod);
        dataGridView1[0,0].Selected = true;
        dataGridView1.Columns[1].Visible = false;
        dataGridView1.Columns[2].Visible = false;
        TotalColumn = new DataGridViewTextBoxColumn();
        TotalColumn.HeaderCell.Value = "Total";
        dataGridView1.Columns.Add(TotalColumn);
        TotalColumn.Visible = false;
        dataGridView1.KeyDown +=new KeyEventHandler(dataGridView1_KeyDown);
    }

    private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Tab)
        {
            dataGridView1.Columns[1].Visible = true;
            dataGridView1.Columns[2].Visible = true;
            dataGridView1.Columns[3].Visible = true;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                dataGridView1[3, i].Value = Convert.ToDouble(dataGridView1[1, i].Value) * Convert.ToDouble(dataGridView1[2, i].Value);

            }

        }

    }

Thanks for replying, i have done all wt i wanted to but now i m facing another problem. when i enter a wrong product code a messagebox appeares but after that the control shifts on the next cell i.e. Product Name. I want that If i enter wrong product code the focus should remain on the current cell. Any idea

My first guess would be the CurrentCell property of the datagrid. For this property you have to know at whitch row you just entered the product code. This is an exemple within the CellValueChanged event of a datagrid:

private void grdSearch_CellValueChanged(Object sender, DataGridViewCellEventArgs e)
{
           grdSearch.CurrentCell = grdSearch.Rows[e.RowIndex].Cells["colProdId"];
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.