【WPF】遍历DataGrid
来源:互联网 发布:mac触摸板怎么右键 编辑:程序博客网 时间:2024/04/30 01:38
///<summary>
/// 获取DataGrid遍历后的数据
///</summary>
///<param name="dg"></param>
///<returns></returns>
publicstring DataGrid(DataGrid dg)
{
try
{
string str = "";
for (int j = 0; j < dg.Items.Count; j++)
{
DataGridCell c = DataGridHelper.GetCell(dg, j, 0);
TextBlock tb = c.Content asTextBlock;
if (str.Equals(string.Empty))
{
str = tb.Text;
}
else
{
str = str +"!" + tb.Text;//直接获取datagrid 遍历后的当前数据
}
}
return str;
}
catch
{
returnnull;
}
}
Class :
以下代码网上扒的~~~~
staticclassDataGridHelper
{
staticpublicDataGridCell GetCell(DataGrid dg, int row, int column)
{
DataGridRow rowContainer = GR(dg, row);
if (rowContainer != null)
{
DataGridCellsPresenter p = GC<DataGridCellsPresenter>(rowContainer);
DataGridCell cell = (DataGridCell)p.ItemContainerGenerator.ContainerFromIndex(column);
if (cell == null)
{
dg.ScrollIntoView(rowContainer, dg.Columns[column]);
cell = (DataGridCell)p.ItemContainerGenerator.ContainerFromIndex(column);
}
return cell;
}
else
{
returnnull;
}
}
staticpublicDataGridRow GR(DataGrid dg, int index)
{
DataGridRow r = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(index);
if (r == null)
{
dg.ScrollIntoView(dg.Items[index]);
r = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(index);
}
return r;
}
static T GC<T>(Visual parent) where T : Visual
{
T child =default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = vas T;
if (child == null)
{
child = GC<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
}
- 【WPF】遍历DataGrid
- wpf datagrid
- WPF DataGrid
- 遍历datagrid
- WPF WebBrowser DataGrid
- wpf datagrid 详细介绍
- wpf button ,datagrid style
- WPF DataGrid Control
- wpf datagrid 数据绑定
- printing DataGrid in WPF
- wpf datagrid 加入checkbox
- WPF DataGrid 绑定Table
- WPF之DataGrid应用
- WPF Datagrid Tooltip
- wpf DataGrid 虚拟化
- WPF分页DataGrid
- WPF DataGrid 分页自定义
- wpf datagrid显示数据
- 面向过程的程序设计
- linux网络编程之tcp的三次握手和四次挥手
- java-可逆加密算法
- TCP协议(保留位URG、PSH,定时器,连接的建立和断开)
- matlab之删除其中一个subplot
- 【WPF】遍历DataGrid
- 合并分支dev的项目到主干trunk中
- ubuntu下安装eclipse C++ 环境步骤记录
- Python IDLE常用快捷键
- 为什么要分层,业务层有什么作用?
- 微信公众号开发(二)
- C++生成和使用dll和lib
- kettle Redhat7连接资源库报错No more handles [MOZILLA_FIVE_HOME=''] (java.lang.UnsatisfiedLinkError: Could n
- 谈谈Mysql之Schema和数据类型优化