DataGridView Problem

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 59
Reputation: Gaurav arora is an unknown quantity at this point 
Solved Threads: 0
Gaurav arora Gaurav arora is offline Offline
Junior Poster in Training

DataGridView Problem

 
0
  #1
Nov 14th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

Re: DataGridView Problem

 
0
  #2
Nov 15th, 2008
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);

}

}

}
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 59
Reputation: Gaurav arora is an unknown quantity at this point 
Solved Threads: 0
Gaurav arora Gaurav arora is offline Offline
Junior Poster in Training

Re: DataGridView Problem

 
0
  #3
Nov 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: EastStreetEagle is an unknown quantity at this point 
Solved Threads: 1
EastStreetEagle EastStreetEagle is offline Offline
Newbie Poster

Re: DataGridView Problem

 
0
  #4
Nov 20th, 2008
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"];
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC