当 AutoGenerateColumns=True 时,有没有办法隐藏 DataGrid 中的特定列? [英] Is there a way to hide a specific column in a DataGrid when AutoGenerateColumns=True?

查看:37
本文介绍了当 AutoGenerateColumns=True 时,有没有办法隐藏 DataGrid 中的特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WPF 4.0 DataGrid,它使用 AutoGenerateColumns=True 绑定到 DataTable.这些列是动态的,但是我知道总会有一个名为 ID 的列,我想隐藏此列.有没有办法做到这一点?

I have a WPF 4.0 DataGrid that is bound to a DataTable using AutoGenerateColumns=True. The columns are dynamic, however I know there is always going to be a column named ID and I would like to hide this column. Is there a way I can do this?

推荐答案

在你的数据网格中,订阅 AutoGeneratingColumn 事件,事件 args (DataGridAutoGeneratingColumnEventArgs) 具有列名和Cancel",如果列名是 ID,则设置 Cancel = true.应该可以解决问题.

in your datagrid, subscribe for the AutoGeneratingColumn event, the event args (DataGridAutoGeneratingColumnEventArgs) has the column name and a "Cancel", if the column name is ID then set Cancel = true. should do the trick.

这篇关于当 AutoGenerateColumns=True 时,有没有办法隐藏 DataGrid 中的特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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