By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Getting data from Datagrid

P: n/a
Hi,
How can I get data frrom a datagrid. eg. if I have a datagrid of 2 columns
and 2 rows, how can I get the data from it into array or variables!!!?

Thanks
--
Regads,
Rochdi
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
How you initialized the DataGrid? If by a datatable, get it from your source
datatable, etc.

[]s
Cesar
"Mike" <Mi**@discussions.microsoft.com> escreveu na mensagem
news:0D**********************************@microsof t.com...
Hi,
How can I get data frrom a datagrid. eg. if I have a datagrid of 2 columns
and 2 rows, how can I get the data from it into array or variables!!!?

Thanks
--
Regads,
Rochdi
Nov 21 '05 #2

P: n/a
Mike wrote:
Hi,
How can I get data frrom a datagrid. eg. if I have a datagrid of 2 columns
and 2 rows, how can I get the data from it into array or variables!!!?

Thanks


Dim DT as DataTable = DirectCast(DataGrid.DataSource, DataTable)
For each Row as DataRow in DT
For ii as integer = 0 to DT.Columns.Count - 1
Debug.Writeline(Row(ii).ToString)
Next
Next

If you didn't supply the datagrid with a datatable, cast it to whatever
you did supply it with.
Nov 21 '05 #3

P: n/a
When I tried its comming up with the following error
"Specified cast is not valid." pointing to:
Dim DT as DataTable = DirectCast(DataGrid.DataSource, DataTable)

--
Regads,
Rochdi
"Chris" wrote:
Mike wrote:
Hi,
How can I get data frrom a datagrid. eg. if I have a datagrid of 2 columns
and 2 rows, how can I get the data from it into array or variables!!!?

Thanks


Dim DT as DataTable = DirectCast(DataGrid.DataSource, DataTable)
For each Row as DataRow in DT
For ii as integer = 0 to DT.Columns.Count - 1
Debug.Writeline(Row(ii).ToString)
Next
Next

If you didn't supply the datagrid with a datatable, cast it to whatever
you did supply it with.

Nov 21 '05 #4

P: n/a
Rochdi,

Did you see this sentence in Chris his message

"cast it to whatever you did supply it with".

I hope this helps,

Cor

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.