473,803 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assign dataGridView cell value to variable

1 New Member
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.Argumen tOutOfRangeExce ption' 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 AllowUserToAddR ows = 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 5292

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

Similar topics

5
21467
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 help system and can't find any help on formatting text. There's plenty of help formatting numbers, dates, and times, though. I'm in the phase of converting from 6 to Net and it seems that even the simplest thing is very, very complicated. And it...
1
4167
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 of the cells in the datagridview and return it back with some other values in an object for another webservice call. The problem is I dont know how to access a cell in a datagridview to do this. Im pretty sure you have to do it thru the binding...
2
2986
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 (so long as it was on a cell or header) and return the value contained in the first column for the selected row and store that as a variable or in a textbox.
3
4662
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 DataGridViewCell 'declare private field _parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex) 'set to a specific cell Debug.Print(_parentDataCell.DataGridView.ToString) 'prints:
3
3956
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 System.EventArgs) Dim result As DialogResult result = MessageBox.Show("Do you really want to quit", "Exit",
0
2507
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 my.
1
13733
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 determining the state of the CheckBox, whether it is checked or not. I have identified an event that fires when the user clicks in the checkbox, CellClick. In that event handler I declare a local variable of the DataGridViewCheckBoxCell type and...
1
4519
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 combobox. The textbox column is going to be coming from a database (actually I could manually create it if i had to). It makes about 20 rows, each with a unique value for the textbox column. The available choices for the combobox row are coming from a...
0
5660
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 blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.