473,321 Members | 1,667 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,321 software developers and data experts.

Assign dataGridView cell value to variable

I am using VC++2008 and am trying to read data enetered in unbound datagridview to implement in function. Under button_click event I entered the following:
Expand|Select|Wrap|Line Numbers
  1. // initialize varaibles from dataGridView
  2. double C1;
  3. double INF1;
  4. double T1;
  5.  
  6. //Read String values from each dataGridView Cell
  7. String^C1s = safe_cast<String^>(dataGridView1[0,0]->Value);
  8. String^INF1s = safe_cast<String^>(dataGridView1[0,1]->Value); 
  9. String^T1s = safe_cast<String^>(dataGridView1[0,2]->Value); 
  10.  
  11. //Convert from String Value to Double 
  12. C1 = Convert::ToDouble(C1s);
  13. INF1 = Convert::ToDouble(INF1s);
  14. T1 = Convert::ToDouble(T1s);
  15.  
The variables are used in a function. Everything compiles fine but when I enter values on first row of datagridview and hit button I get

"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Index was out of range. Must be non-negative and less than the size of the collection."

I have added following code to form to restrict number of rows as defined in numericupdown box
Expand|Select|Wrap|Line Numbers
  1. private: System::Void dataGridView1_RowEnter(System::Object^  sender, System::Windows::Forms::DataGridViewCellEventArgs^  e)     //raises event handler 
  2.  
  3. {    
  4.   int NUMST;
  5.   NUMST = safe_cast<int>(this->numericUpDown1->Value); //Input from numericUpDown box
  6.   if (this->dataGridView1->RowCount > NUMST) 
  7.          this->dataGridView1->AllowUserToAddRows = false; 
  8. }
  9.  
The number of rows is restricted ok, but I believe that once the AllowUserToAddRows = false the RowIndex is set to -1 and its throwing the out of range error.

Would anybody have a suggestion on how to make this work, or is there a better way to read data from unboubnd datagrid and assign each cell to double numeric variable to be used in function? Thank you.
Nov 19 '08 #1
0 5204

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

Similar topics

5
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net...
1
by: Riley | last post by:
Need some help. I am using datagridview in 2005 with C#. I am calling a web service and filling the datagridview with the data returned. This all works fine. Next step is to take a value from one...
2
by: Karl | last post by:
Hi all, I'm reasonably new to csharp so you have to forgive me asking what may be a stupid question... As I said, I'm new to CSharp but in VB I was able to click anywhere on a DataGridView...
3
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As...
3
by: GrispernMix | last post by:
Imports System.Windows.Forms Imports System.Convert Imports Microsoft.VisualBasic.Financial Public Class Chapter7 Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As...
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...
1
by: zacks | last post by:
Using VS 2005. I have an app that has a DataGridView control. This control has two columns, the first column is a standard TextBox, and the second column is a CheckBox. I am having difficulty...
1
Plater
by: Plater | last post by:
I feel like this question has been asked before, but I couldn't find it. I think I am missing something obvious. Basically I am going to have a DataGridView with two columns. One textbox, one...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.