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

Trying to get values of each column in a datagrid view

I am usign the code below to find the current row and cell. Which works OK.
Then hwat I want to do is get the value of each other cell in the row. So
below I am trying to get at least one values. The last line gives me an error
that I am not passing the correct arguments. But I am passing two integers,
one for the row and one for the cell. Any ideas how I can achieve this feat?

// gets the current row and cell being edited.
string msg = String.Format("Row: {0}, Column: {1}",
scriptDataGridView.CurrentCell.RowIndex,
scriptDataGridView.CurrentCell.ColumnIndex);
//MessageBox.Show(msg, "Current Cell");
rowNumber = msg.Substring(5, 1);
colNumber = msg.Substring(16, 1);
int.Parse(rowNumber);
int.Parse(colNumber);

command = scriptDataGridView[colNumber, rowNumber].FormattedValue.ToString();
Feb 7 '07 #1
2 1543
Chris wrote:
I am usign the code below to find the current row and cell. Which works
OK. Then hwat I want to do is get the value of each other cell in the row.
So below I am trying to get at least one values. The last line gives me an
error that I am not passing the correct arguments. But I am passing two
integers, one for the row and one for the cell. Any ideas how I can
achieve this feat?

// gets the current row and cell being edited.
string msg = String.Format("Row: {0}, Column: {1}",
scriptDataGridView.CurrentCell.RowIndex,
scriptDataGridView.CurrentCell.ColumnIndex);
//MessageBox.Show(msg, "Current Cell");
rowNumber = msg.Substring(5, 1);
colNumber = msg.Substring(16, 1);
int.Parse(rowNumber);
int.Parse(colNumber);

command = scriptDataGridView[colNumber,
rowNumber].FormattedValue.ToString();
Well, it seems that you are parsing the numbers but not assigning to any
variable, you could so what u want in two ways:
1) command = scriptDataGridView[int.Parse(colNumber),
int.Parse(rowNumber)].FormattedValue.ToString();
Or the cleaner way...
2)
int rowNum = int.Parse(rowNumber);
int colNum = int.Parse(colNumber);
scriptDataGridView[colNum, rowNum].FormattedValue.ToString();
I hope it helps.
--
----
VoidMain
Feb 7 '07 #2
Thank you! Thank you! Thank you! Works great.
"Jerónimo Milea" wrote:
Chris wrote:
I am usign the code below to find the current row and cell. Which works
OK. Then hwat I want to do is get the value of each other cell in the row.
So below I am trying to get at least one values. The last line gives me an
error that I am not passing the correct arguments. But I am passing two
integers, one for the row and one for the cell. Any ideas how I can
achieve this feat?

// gets the current row and cell being edited.
string msg = String.Format("Row: {0}, Column: {1}",
scriptDataGridView.CurrentCell.RowIndex,
scriptDataGridView.CurrentCell.ColumnIndex);
//MessageBox.Show(msg, "Current Cell");
rowNumber = msg.Substring(5, 1);
colNumber = msg.Substring(16, 1);
int.Parse(rowNumber);
int.Parse(colNumber);

command = scriptDataGridView[colNumber,
rowNumber].FormattedValue.ToString();
Well, it seems that you are parsing the numbers but not assigning to any
variable, you could so what u want in two ways:
1) command = scriptDataGridView[int.Parse(colNumber),
int.Parse(rowNumber)].FormattedValue.ToString();
Or the cleaner way...
2)
int rowNum = int.Parse(rowNumber);
int colNum = int.Parse(colNumber);
scriptDataGridView[colNum, rowNum].FormattedValue.ToString();
I hope it helps.
--
----
VoidMain
Feb 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Programmer | last post by:
Hi All Here is my problem I'm using a SQLDataAdapter and DataSet I use the method FillSchema(myDataset, SchemaType.Source) The problem is that when i Check the default Values of the Dataset...
1
by: dbuchanan | last post by:
VB.NET 2003 / SQLS2K The Stored Procedure returns records within Query Analyzer. But when the Stored Procedure is called by ADO.NET ~ it produced the following error message. ...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
2
by: Balamurukan | last post by:
How to retrive property values from our own property window
2
by: Colin McGuigan | last post by:
This is a translation of an ASP page to ASP.Net. First, the background: The goal is to have a grid of different settings for the application -- think something along the lines of the Property...
13
by: scorpion53061 | last post by:
Very urgent and I am very close but need a little help to get me over the edge........ I need to write these columns to a html file with each row containing these columns (seperated by breaks)....
1
by: Ken Varn | last post by:
I have a problem where my DataGrid would not maintain the ViewState of my databound rows. I finally narrowed down the problem. If my first column is a template column, the view state for the...
1
by: nemo | last post by:
I'm creating a datasource and populating a datagrid at runtime. The code is as follows: dt = New DataTable dt.Columns.Add(New DataColumn("Item", GetType(String))) dt.Columns.Add(New...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.