| | |
DataGridView Problem
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 59
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Oct 2007
Posts: 172
Reputation:
Solved Threads: 16
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);
}
}
}
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);
}
}
}
•
•
Join Date: Mar 2007
Posts: 59
Reputation:
Solved Threads: 0
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
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 1
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"];
}
private void grdSearch_CellValueChanged(Object sender, DataGridViewCellEventArgs e)
{
grdSearch.CurrentCell = grdSearch.Rows[e.RowIndex].Cells["colProdId"];
}
![]() |
Similar Threads
- Image in DataGridView (C#)
- How to add rows from dataset to datagridview (C#)
- DataGridView (C#)
- Datagridview problem (VB.NET)
- checkbox in datagridview c# (C#)
- DataGridView EASY HELP (VB.NET)
Other Threads in the C# Forum
- Previous Thread: crystal report problem
- Next Thread: detecting pixelated parts of the picture
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast button buttons c# check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing editing enabled encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener load mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post print programming radians regex remote remoting resolved. richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer update user usercontrol validation view visualstudio webbrowser windows winforms wpf xml





