Click to See Complete Forum and Search --> : [RESOLVED] Get data from DataGridView
Zeldan
May 26th, 2009, 01:45 AM
Hello everyone.I have a problem with reading data from DataGridView to array. Use code:
int[,] n = new int[3,19];
for (int i = 1; i <= StartDataView.Rows.Count; i++)
{
for (int j = 1; j <= StartDataView.Columns.Count; j++)
{
n[i - 1, j - 1] = (int)StartDataView.Rows[i].Cells[j].Value;
}
}
but all values results is "null";in this case:
n[i - 1, j - 1] = int.Parse(StartDataView.Rows[i].Cells[j].Value.ToString());
get "0";
What I do wrong?
JonnyPoet
May 26th, 2009, 05:40 AM
Hello everyone.I have a problem with reading data from DataGridView to array. Use code:
....
What I do wrong?At first please use codetags,( thats what you do wrong here in this forum :D ) So please edit your post. Without codetags code losts formatting.
we do not know if your grid contains integers. Are you sure ? maybe it contains strings, so what contains your grid. Please show a screenshot maybe so we can see
Zeldan
May 26th, 2009, 09:25 AM
int[,] n = new int[3, 19];
for (int i = 0; i < (StartDataView.Rows.Count - 1); i++)
{
for (int j = 0; j < StartDataView.Columns.Count; j++)
{
try
{
n[i, j] = int.Parse(this.StartDataView.Rows[i].Cells[j].Value.ToString());
}
catch (Exception Ee)
{ //get exception of "null"
MessageBox.Show(Ee.ToString());
}
}
}
JonnyPoet,thanks you for helping me,not only in understanding of my program mistakes...
Above the code, I have a StringGridView ,it's bind with BindingSource,user may enter the numbers(with int type) ...but when I debugging ,value is "NULL" ,add some attachments...
JonnyPoet
May 26th, 2009, 02:01 PM
I tested your code in the added project and as you will see it works.
So the problem must be elsewhere maybe in the databinding itself ?
Zeldan
May 26th, 2009, 02:21 PM
Thank you very much JonnyPoet,your example helps me to understand my mistakes..i have only binding source in my project,but when i do like in yor example it works!!
JonnyPoet
May 26th, 2009, 03:06 PM
Thank you very much JonnyPoet,your example helps me to understand my mistakes..i have only binding source in my project,but when i do like in yor example it works!!
You are welcome
:wave:
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.