Small is New Big in C#

Coding

DataGridView numeric question

leave a comment »

How do you add numeric values and display these values in this
control.

EX: col 1 has $100.00, col 2 has $200.00, column 3 then displays the
total in the control which is calculated > $300.00.

My question is for horizontal calculation and vertical calculation
within the datagridview.

Also if possible provide binding answers and runtime answers
PLEASE!!!


I have written a sample of horizontal calculation to you <br/>
<br/>
dgvDepartment is datagridview<br/>
<br/>
<br/>
private void frmDepartManage_Load(object sender, EventArgs e)<br/>
{<br/>
<br/>
DataSet ds = this.GetDs("SELECT Bin,Quantity FROM Production.ProductInventory","Production.ProductInventory");//get your dataset<br/>
ds.Tables[0].Columns.Add("Total", typeof(<span style="color:#a31515">Decimal</span>
)); // add new column to calculate total<br/>
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)<br/>
{<br/>
ds.Tables[0].Rows[i][2] = Convert.ToDecimal(ds.Tables[0].Rows[i][0]) + Convert.ToDecimal(ds.Tables[0].Rows[i][1]);<br/>
}<br/>
<br/>
dgvDepartment.DataSource = ds.Tables[0];<br/>
}<br/>
<br/>
<br/>
//if total> 300.00 then displays<br/>
private void dgvDepartment_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)<br/>
{<br/>
string colName = this.dgvDepartment.Columns[e.ColumnIndex].Name.ToString();<br/>
if (colName == "Total")<br/>
{<br/>
<br/>
if (Convert.ToDecimal(e.Value) < 300.00)<br/>
{<br/>
<br/>
e.Value = "";<br/>
e.FormattingApplied = true;<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
}
Advertisements

Written by nauhil

June 14, 2010 at 11:07 am

Posted in Q&A

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: