943,929 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2256
  • C# RSS
Nov 14th, 2008
0

DataGridView Problem

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Gaurav arora is offline Offline
59 posts
since Mar 2007
Nov 15th, 2008
0

Re: DataGridView Problem

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);

}

}

}
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Nov 19th, 2008
0

Re: DataGridView Problem

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Gaurav arora is offline Offline
59 posts
since Mar 2007
Nov 20th, 2008
0

Re: DataGridView Problem

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"];
}
Reputation Points: 10
Solved Threads: 1
Newbie Poster
EastStreetEagle is offline Offline
5 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: crystal report problem
Next Thread in C# Forum Timeline: detecting pixelated parts of the picture





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC