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

问题描述

我有一个绑定到 ObjectDataSource 的 DataGridView,其中一些列是隐藏的,包括 ID 列.问题是,即使 ID 列的可见属性设置为 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:
尝试在 FormLoad 事件中将 DGV 列的 Visible 属性显式设置为 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 ID 列不会隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:52