Datagrid
Hi everyone,
May i know how to read all the values in a datagrid one by one. I want to add all the values in each row in a particular column in the datagrid. Is it possible to do so?
Hi everyone,
May i know how to read all the values in a datagrid one by one. I want to add all the values in each row in a particular column in the datagrid. Is it possible to do so?
LynnOoi wrote:
Hi everyone,
May i know how to read all the values in a datagrid one by one. I want to add all the values in each row in a particular column in the datagrid. Is it possible to do so?
Are these values that you want to read stored some where, the datagrid can be assigned to the datasource to retrieve data you want.
refer http://www.codeproject.com/cs/miscctrl/csharpgridcontrol.asp
http://p2p.wrox.com/topic.asp?TOPIC_ID=15360
hope these links would help
Hi,
You would have to iterate through each row on the datagrid and get the column value for each row and keep adding them.
int numRows = datagrid1.Rows.Count;
int sum = 0;
for (int i = 0; i< numRows; i++)
{
int colValue = datagrid1[columnIndex, i].Value; //Typecase this value appropriately
sum = sum + colValue;
}
Console.WriteLine ("sum is "+sum);
Hi,
I have try to apply those codes in my program but there is an error saying that datagrid does not contain rows property.
You could get the row counts through DataTable which should be the datagrid's datasource.
int row = dt.Rows.Count;
Hi,
I use dt.Rows.Count also cannot. There is an error occur. What should I do?
Here is the error message :
Compiler Error Message: CS0117: 'System.Data.SqlClient.SqlDataReader' does not contain a definition for 'Rows'
Source Error:
Line 30: DataGrid1.Visible = result; |
A DataTable is an 'invisible' control that is part of ADO .NET 1.0 and above.
Suggest you either get a book on ADO.NET or Visual Studio/Basic .NET 2002 or later....not VB6 or earlier or check the MSDN library if you have access to it. Infact of the data components are in the Data folder (not the Toolbox).
Bye,
In addition...
A dataview can be used to search for rows using the row filter - this is definitely in the Data Folder - You may find it easier to use this....?