DataGridView的标识列不会躲 [英] DataGridView ID Column Will Not Hide

查看:104
本文介绍了DataGridView的标识列不会躲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绑定到一个ObjectDataSource某些列被隐藏,包括ID列一个DataGridView。问题是,ID列显示出来,即使其visible属性设置为false。有没有人遇到这个问题之前?宽度设置为零是不是一种选择,因为网格不允许列的宽度宽小于5个像素,以便它仍然显示网格上的柱不管是什么。

I have a DataGridView bound to an ObjectDataSource some of the columns are hidden including the ID column. The problem is that the ID column shows up even when its visible property is set to false. Has anyone run into this problem before? Setting the width to zero is not an option since the grid doesn't allow columns with a width less than 5 pixels wide so it still shows the column on the grid no matter what.

但奇怪的是,该ID列并不总是显示。我的工作是应用了一会儿后,列又出现​​了。

The strange thing is that the ID column wasn't always showing. After I worked on the app for a bit the columns appeared again.

DataGridView中没有设置为自动生成列。我建立以.NET和C#4.0的版本。

DataGridView is not set to auto generate columns. I am building to version 4.0 of .NET and C#.

下面是在窗体构造函数中的代码。

Here is the code in the form constructor.

dgvActiveMiners.AutoGenerateColumns = false;
dgvAvilableMiners.AutoGenerateColumns = false;
dgvOperationResults.AutoGenerateColumns = false;

dgvActiveMiners.Columns["dgvActiveMinersRecordId"].Visible = false;
dgvAvilableMiners.Columns["dgvAvilableMinersRecordId"].Visible = false;
dgvOperationResults.Columns["dgvOperationResultRecordId"].Visible = false;

这是针对网格生成的代码

This is the generated code for the grids.

this.dgvOperationResults.AllowUserToAddRows = false;
this.dgvOperationResults.AllowUserToDeleteRows = false;
this.dgvOperationResults.AutoGenerateColumns = false;
this.dgvOperationResults.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvOperationResults.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.dgvOperationResultRecordId,
this.nameDataGridViewTextBoxColumn2,
this.typeIdDataGridViewTextBoxColumn,
this.amountDataGridViewTextBoxColumn,
this.operationIdDataGridViewTextBoxColumn});
this.dgvOperationResults.DataSource = this.operationResultBindingSource;
this.dgvOperationResults.Location = new System.Drawing.Point(12, 40);
this.dgvOperationResults.MultiSelect = false;
this.dgvOperationResults.Name = "dgvOperationResults";
this.dgvOperationResults.ReadOnly = true;
this.dgvOperationResults.Size = new System.Drawing.Size(498, 247);
this.dgvOperationResults.TabIndex = 16;



我不知道我可能会错过什么吗?

I don't know what else I could be missing?

感谢

推荐答案

建议1:结果
尝试DGV列的Visible属性在FormLoad事件明确设置为false:

Suggestion 1:
Try explicitly setting the DGV Column's Visible property to false in the FormLoad event:

dataGridView.Columns["YourIdColumn"].Visible = false;



建议2:结果
试着改变你的专栏dgvActiveMinersRecordId从DGV到最后一列的第一列。

Suggestion 2:
Try changing your column dgvActiveMinersRecordId from the first column in the DGV to the last column.

这篇关于DataGridView的标识列不会躲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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