473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Datagridview First Row Skip

maheshwag
software use: c#, VS-2005

I am trying to calculation on datagridview as below

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
  3. {
  4.    double dd = 1.768901;
  5.    dd = Convert.ToDouble(dd.ToString("f2"));
  6.    DataGridViewCellStyle fixedstyle = 
  7.    new DataGridViewCellStyle();
  8.    fixedstyle.Format = "f2";
  9.    dataGridView1.Columns[1].DefaultCellStyle =fixedstyle;
  10.  
  11.    try
  12.    {
  13.     decimal sum = 0.00m;
  14.  
  15.     for (int i = 0; i < dataGridView1.Rows.Count - 1;i++)
  16.     if (dataGridView1[1, i].Value != DBNull.Value)
  17.     {
  18.     sum=sum Convert.ToDecimal(dataGridView1[1,i].Value);
  19.     label12.Text = sum.ToString("f2");
  20.      }
  21.  
  22.    }
  23.  
  24.     catch (Exception ex)
  25.     {
  26.        MessageBox.Show(ex.Message);
  27.     }
  28.    }
  29.  
  30.  
The Problem is Total count from 2nd row not from begining rows.
e.g. :-

1st rows column value=12
2nd rows column value=12
3rd rows column value=12

The total shows 24 where actual totals is 36.

I think the datagridview skip first rows. How can i solve it?.

Note:- I set ColumnHeaderVisible property set to false.
Oct 5 '10 #1
3 4743
mzmishra
390 Expert 256MB
why u have i < dataGridView1.Rows.Count - 1.either make it i <= dataGridView1.Rows.Count - 1 or make it i < dataGridView1.Rows.Count
Oct 5 '10 #2
1. With i<= dataGridView1.Rows.Count-1 result is 0.00
e.g. if 1st row column value i enter 12.00 the total count result is 0.00

2. With i<dataGridView1.Rows.Count Result is Error like Index was out of range. Index Must be non negative and less than size of collection parameter name:index
Oct 6 '10 #3
I wants to Share a knowledge with solution of above problem

The solution is:

Expand|Select|Wrap|Line Numbers
  1.     private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
  2.         {
  3.             decimal sum = 0.00m;
  4.  
  5.             for (int i = 0; i < dataGridView1.Rows.Count; i++)
  6.             {
  7.                 if (dataGridView1[1, i].Value != DBNull.Value)
  8.                 {
  9.                     sum = sum + Convert.ToDecimal(dataGridView1[1, i].Value);
  10.                     textBox1.Text = sum.ToString("f2");
  11.  
  12.                 }
  13.  
  14.             }
  15.         }
  16.  
  17.  
Just change the event to dataGridView_CellValidated.
Oct 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

59
by: AK | last post by:
I tried to google "skip scan DB2" but came up with nothing. Does DB2 have the feature under a different name?
10
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header...
1
by: Dave A | last post by:
Hi, I am struggling with two way databinding in WinForms and the DataGridView. I am binding to business object classes (rather than datatables). If I have a collection of these business...
0
by: Bails | last post by:
Hi All, im in the process of teaching myself VB Express and have chosen to make a Poker Timer as my first project. The project essentially consists of 2 forms as follows: Form1 Contains a...
2
by: mrstrong | last post by:
Gday, I have a datagridview that I am creating the columns programatically which all seems to work fine. I have a couple of dropdown boxes, so I have set the editMode= EditOnEnter. Now my...
2
by: mrstrong | last post by:
Gday, Why would all my checkboxes inside a datagridview stop working (ie checked state not updating when user clicks) when the datagridview's editmode property is changed to "EditOnEnter"? It...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
by: Aegixx | last post by:
Ok, extremely wierd situation here: (I'll post the code below, after the explanation) I've got a Windows application (.NET 3.5) that has a single Form with a DataGridView embedded. The user...
5
by: bill | last post by:
When you retrieve records to diplay in a DataGridView control the first record has the background highlighted even though no row is yet selected. Does anyone know a way to suppress this first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.