我在 WinForms 2.0 应用程序中有一个 DataGridView,它有很多列,即使在最大化时用户也必须滚动才能看到所有列。最右边的列是一个删除按钮。我们希望始终显示删除按钮,而无需用户水平滚动。
当我尝试设置
column.Frozen = true;
时,它会删除我的水平滚动条并冻结所有先前的列。根据Microsoft,这是设计使然。
有人对此有解决方案吗?
这是 VS 2005 的错误报告:https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=117002&wa=wsignin1.0#
微软似乎不关心纠正这个问题。 “按设计”?真是个笑话。
试试这个:
var cols = dcols.ToArray();//dcols is the DataGridViewColumn List wait to add to DataGridView
if (cols.Last().Frozen)
{
_this.RightToLeft = RightToLeft.Yes;
cols = cols.Reverse().ToArray();
}
_this.Columns.AddRange(cols);
//Note that DataGridView does not allow freezing on both sides at the same time, or freezing some columns in the middle.
你会遇到问题。滚动条将位于最右侧。那么,你可以试试下面的代码:
//OnDataBindingComplete
if (this.Columns.Count > 0)
this.FirstDisplayedScrollingColumnIndex = this.Columns.Count - 1;