如何将DataGrid转换为dataTable [英] How to convert DataGrid to dataTable

查看:514
本文介绍了如何将DataGrid转换为dataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不使用任何循环将所有datagrid记录复制到datatable中。
对于Ex:

I want to copy all the datagrid records into datatable without using any loop. For Ex:

Dim dt as New DataTable
dt = Datagrid1.Items

但这无法正常工作并给出错误消息。

But this is not Working and giving an error message.

我的开发平台是Visual Studio 2010,语言是带有vb.net 4.0的WPF。

My Development platform is Visual studio 2010 and language is WPF with vb.net 4.0

推荐答案

这是传输所有记录的方式

This is the way to transfer all the records from DATAGRID to DATATABLE without using the LOOP.

VB:

Dim dt As New DataTable
dt = CType(DataGrid1.ItemsSource, DataView).ToTable

C#:

DataTable dt = new DataTable();
dt = ((DataView)DataGrid1.ItemsSource).ToTable();  

这篇关于如何将DataGrid转换为dataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆