具有自定义列的 DataGridView 和 DataBinding

发布于 2024-09-18 05:47:30 字数 349 浏览 2 评论 0原文

我的要求如下,我正在调用一个过程并填充一个DataTable。假设该过程返回emp_idemp_name、名称和状态。当我使用 DataGridView1.DataSource = 时,我将所有列填充到 DataGridView 中。如何仅显示 DataGridView 中选定的列。例如,我只想显示 emp_idemp_name

同样,您能否帮助我了解如何通过编写代码来增加 DataGridView 列的宽度。

My requirement is as follows, I am calling a procedure and I'm populating a DataTable. Assume that the procedure is returning emp_id, emp_name, designation and status. When I use DataGridView1.DataSource = <Name of the DataTable>, I get all the columns populated into the DataGridView. How can I display only selected columns in the DataGridView. For e.g, I want to show only emp_id and emp_name.

Similarly, can you please help me as to how I can increase the width of the columns of the DataGridView by writing code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤千羽 2024-09-25 05:47:31

您可以非常轻松地选择并自定义网格上的列

You can quite easily select and customize the columns on the grid.

夕色琉璃 2024-09-25 05:47:30

您可以将网格的 AutoGenerateColumns 属性设置为 False 并手动添加所需的列。不要忘记,您需要将每个 Grid-Column 的 DataPropertyName 设置为 DataTable-Column 的名称。

编辑:如果您想更改列的宽度,只需设置“宽度”或“填充模式”属性即可。

You can set the AutoGenerateColumns-Property of the Grid to False and add the columns you want by hand. Don't forget that you need to set the DataPropertyName of each Grid-Column to the name of the DataTable-Column.

Edit: If you want to change the width of the columns, simply set the 'Width' or the 'FillMode'-Property.

稀香 2024-09-25 05:47:30

与 Bobby 的方法相反的是,允许 DataGridView 自动生成列,然后使用 dataGrid.Columns("designation").Visible = False. 隐藏列。此方法的优点之一是您不必对隐藏的列进行硬编码。

The opposite of Bobby's method is to allow the DataGridView autogenerate the columns and then hide your columns by using dataGrid.Columns("designation").Visible = False.. One of the advantages of this method is that you don't have to hardcode which columns your hiding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文