将列添加到DataGridView(VB.NET) [英] Add column to DataGridView (VB.NET)

查看:636
本文介绍了将列添加到DataGridView(VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目中添加一个新列,但是发生了一件奇怪的事情……

I would like to add a new column in my project, but a weird thing happened...

我的代码

adapter.fill(datatable)
dgv.datasource = datatable
dgv.columns.add("test","testHeader")

测试列的列索引应该是最后一个索引。
但是,我发现列索引为0,原始的第0个索引变为1

The column index of test column should be the last index. However, I found the column index is 0 and the original 0th index turns to 1

我不确定发生了什么。是否有任何因素可能导致此问题? datagridview的
属性设置错误吗?

I am not sure what happened. Is there any factor could cause this problem? property settings of datagridview is wrong?

推荐答案

有一个 DataGridViewColumn.DisplayedIndex 属性来控制可见列的顺序。

There's a DataGridViewColumn.DisplayedIndex property to control order of visible columns.

请记住,DataGridView会跟踪这些值并为网格中的其他列更新它们。将其中一些更改为0会将所有其他列更新为更高的值。

Keep in mind that DataGridView tracks theese values and update them for other columns in your grid. Chaning some of them to 0 will update all other columns to highter values.

这篇关于将列添加到DataGridView(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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