C# 中的 DataGridView 上的垂直滚动条不断消失
我们正在 Visual Studio C# 2008 Express Edition 中构建一个 Windows 应用程序,从服务器返回数据集并将其显示在 DataGridView 中。某些用户抱怨在工作时垂直滚动条不断消失。他们可以通过关闭该屏幕并重新打开它来恢复它。
我们正在努力调试这个问题,因为它不会一直发生,也不会发生在某些用户(包括我们所有的开发人员)身上。
当滚动条消失时,它会留下它所占据的空间,但我们没有显示控件,而是得到了渐变的蓝色(看起来与此时屏幕的背景非常一致)。
我最初的感觉是这可能是 DataGridView 控件中的一个错误。你们中有人以前遇到过这样的错误吗?您能否就从哪里开始修复它提供任何建议?
我们正在运行的代码是: 我的同事(正在开发此屏幕)为您提供了以下代码: // // dGridJournal // this.dGridJournal.AllowUserToAddRows = false; this.dGridJournal.AllowUserToDeleteRows = false; this.dGridJournal.AllowUserToResizeRows = false; this.dGridJournal.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left ) | System.Windows.Forms.AnchorStyles.Right))); this.dGridJournal.AutoGenerateColumns = false; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dGridJournal.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; this.dGridJournal.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dGridJournal.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.jrnhidDataGridViewTextBoxColumn, this.typedesc, this.pdateDataGridViewTextBoxColumn, this.narridDataGridViewTextBoxColumn, this.pvalueDataGridViewTextBoxColumn, this.authdesc}); this.dGridJournal.DataCont = this.dataContJournalEnquiries; this.dGridJournal.DataSource = this.ttJRNHeaderBindingSource; dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False; this.dGridJournal.DefaultCellStyle = dataGridViewCellStyle3; this.dGridJournal.LabelText = "请输入必填条件。"; this.dGridJournal.Location = new System.Drawing.Point(4, 4); this.dGridJournal.ModifiedCellColor = System.Drawing.Color.SandyBrown; this.dGridJournal.MultiSelect = false; this.dGridJournal.Name = "dGridJournal"; this.dGridJournal.ReadOnly = true; dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dGridJournal.RowHeadersDefaultCellStyle = dataGridViewCellStyle4; this.dGridJournal.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dGridJournal.Size = new System.Drawing.Size(488, 95); this.dGridJournal.TabIndex = 1; this.dGridJournal.TabStop = false; this.dGridJournal.UpScroll = true; this.dGridJournal.SortStarted += new CapitaHartshead.Core.Controls.CHDataGridView.SortStartingHandler(this.dGridJournal_SortStarted); this.dGridJournal.SelectionChanged += new System.EventHandler(this.dGridJournal_SelectionChanged); // // jrnhidDataGridViewTextBoxColumn // this.jrnhidDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader; this.jrnhidDataGridViewTextBoxColumn.DataPropertyName = "jrnhid"; this.jrnhidDataGridViewTextBoxColumn.HeaderText = "期刊编号"; this.jrnhidDataGridViewTextBoxColumn.Name = "jrnhidDataGridViewTextBoxColumn"; this.jrnhidDataGridViewTextBoxColumn.ReadOnly = true; this.jrnhidDataGridViewTextBoxColumn.Width = 97; // // typedesc // this.typedesc.DataPropertyName = "typedesc"; this.typedesc.HeaderText = "类型"; this.typedesc.Name = "typedesc"; this.typedesc.ReadOnly = true; this.typedesc.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; this.typedesc.Width = 55; // // pdateDataGridViewTextBoxColumn // this.pdateDataGridViewTextBoxColumn.DataPropertyName = "pdate"; this.pdateDataGridViewTextBoxColumn.HeaderText = "日期"; this.pdateDataGridViewTextBoxColumn.Name = "pdateDataGridViewTextBoxColumn"; this.pdateDataGridViewTextBoxColumn.ReadOnly = true; this.pdateDataGridViewTextBoxColumn.Width = 80; // // narridDataGridViewTextBoxColumn // this.narridDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.narridDataGridViewTextBoxColumn.DataPropertyName = "narr"; this.narridDataGridViewTextBoxColumn.HeaderText = "描述"; this.narridDataGridViewTextBoxColumn.Name = "narridDataGridViewTextBoxColumn"; this.narridDataGridViewTextBoxColumn.ReadOnly = true; this.narridDataGridViewTextBoxColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; // // pvalueDataGridViewTextBoxColumn // this.pvalueDataGridViewTextBoxColumn.DataPropertyName = "pvalue"; dataGridViewCellStyle2.Format = "C2"; dataGridViewCellStyle2.NullValue = null; this.pvalueDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2; this.pvalueDataGridViewTextBoxColumn.HeaderText = "值"; this.pvalueDataGridViewTextBoxColumn.Name = "pvalueDataGridViewTextBoxColumn"; this.pvalueDataGridViewTextBoxColumn.ReadOnly = true; this.pvalueDataGridViewTextBoxColumn.Width = 80; // // authdesc // this.authdesc.DataPropertyName = "authdesc"; this.authdesc.HeaderText = "状态"; this.authdesc.Name = "authdesc"; this.authdesc.ReadOnly = true; this.authdesc.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; this.authdesc.Width = 50;
We're building a Windows application in Visual Studio C# 2008 Express Edition, returning a data set from our server and displaying it in a DataGridView. Certain users are complaining that the vertical scroll bar keeps vanishing when they're working. They can restore it by closing down that screen and re-opening it.
We're struggling to debug this problem because it doesn't happen all the time and never happens to some users (including all of our developers).
When the scrollbar has vanished, it leaves the space that it occupied, but instead of displaying the control, we get a graduated blue colour (which looks very much line the backdrop of the screen at that point).
My initial feeling is that this could be a bug in the DataGridView control. Have any of you encountered such an error before? Can you offer any sugestions on where to start fixing it?
The code that we're running is:
My collegue (who's developing this screen) has provided the following code for you: // // dGridJournal // this.dGridJournal.AllowUserToAddRows = false; this.dGridJournal.AllowUserToDeleteRows = false; this.dGridJournal.AllowUserToResizeRows = false; this.dGridJournal.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dGridJournal.AutoGenerateColumns = false;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dGridJournal.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; this.dGridJournal.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dGridJournal.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.jrnhidDataGridViewTextBoxColumn, this.typedesc, this.pdateDataGridViewTextBoxColumn, this.narridDataGridViewTextBoxColumn, this.pvalueDataGridViewTextBoxColumn, this.authdesc});
this.dGridJournal.DataCont = this.dataContJournalEnquiries; this.dGridJournal.DataSource = this.ttJRNHeaderBindingSource; dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False; this.dGridJournal.DefaultCellStyle = dataGridViewCellStyle3; this.dGridJournal.LabelText = "Please enter mandatory criteria."; this.dGridJournal.Location = new System.Drawing.Point(4, 4); this.dGridJournal.ModifiedCellColor = System.Drawing.Color.SandyBrown; this.dGridJournal.MultiSelect = false;
this.dGridJournal.Name = "dGridJournal"; this.dGridJournal.ReadOnly = true; dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dGridJournal.RowHeadersDefaultCellStyle = dataGridViewCellStyle4; this.dGridJournal.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dGridJournal.Size = new System.Drawing.Size(488, 95); this.dGridJournal.TabIndex = 1; this.dGridJournal.TabStop = false; this.dGridJournal.UpScroll = true;
this.dGridJournal.SortStarted += new CapitaHartshead.Core.Controls.CHDataGridView.SortStartingHandler(this.dGridJournal_SortStarted); this.dGridJournal.SelectionChanged += new System.EventHandler(this.dGridJournal_SelectionChanged); // // jrnhidDataGridViewTextBoxColumn // this.jrnhidDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader; this.jrnhidDataGridViewTextBoxColumn.DataPropertyName = "jrnhid"; this.jrnhidDataGridViewTextBoxColumn.HeaderText = "Journal Number";
this.jrnhidDataGridViewTextBoxColumn.Name = "jrnhidDataGridViewTextBoxColumn"; this.jrnhidDataGridViewTextBoxColumn.ReadOnly = true; this.jrnhidDataGridViewTextBoxColumn.Width = 97; // // typedesc // this.typedesc.DataPropertyName = "typedesc"; this.typedesc.HeaderText = "Type"; this.typedesc.Name = "typedesc"; this.typedesc.ReadOnly = true; this.typedesc.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; this.typedesc.Width = 55; // // pdateDataGridViewTextBoxColumn // this.pdateDataGridViewTextBoxColumn.DataPropertyName = "pdate";
this.pdateDataGridViewTextBoxColumn.HeaderText = "Date"; this.pdateDataGridViewTextBoxColumn.Name = "pdateDataGridViewTextBoxColumn"; this.pdateDataGridViewTextBoxColumn.ReadOnly = true; this.pdateDataGridViewTextBoxColumn.Width = 80; // // narridDataGridViewTextBoxColumn // this.narridDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.narridDataGridViewTextBoxColumn.DataPropertyName = "narr"; this.narridDataGridViewTextBoxColumn.HeaderText = "Description";
this.narridDataGridViewTextBoxColumn.Name = "narridDataGridViewTextBoxColumn"; this.narridDataGridViewTextBoxColumn.ReadOnly = true; this.narridDataGridViewTextBoxColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; // // pvalueDataGridViewTextBoxColumn // this.pvalueDataGridViewTextBoxColumn.DataPropertyName = "pvalue"; dataGridViewCellStyle2.Format = "C2"; dataGridViewCellStyle2.NullValue = null; this.pvalueDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2; this.pvalueDataGridViewTextBoxColumn.HeaderText = "Value";
this.pvalueDataGridViewTextBoxColumn.Name = "pvalueDataGridViewTextBoxColumn"; this.pvalueDataGridViewTextBoxColumn.ReadOnly = true; this.pvalueDataGridViewTextBoxColumn.Width = 80; // // authdesc // this.authdesc.DataPropertyName = "authdesc"; this.authdesc.HeaderText = "State"; this.authdesc.Name = "authdesc"; this.authdesc.ReadOnly = true; this.authdesc.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; this.authdesc.Width = 50;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们确实尝试隐藏并重新显示滚动条,但这并不成功。
我们还尝试在更新数据时禁用数据网格视图,然后在完成后重新启用它。我们还没有收到这是否有效的回复。
We did try hiding and re-displaying the scroll bar, but this was unssuccessful.
We've also tried disabling the datagrid view while we update the data, then re-enabeling it once complete. We've not yet heard back whether this worked or not.
经过一番挖掘后,我们已经能够可靠地复制该问题。它似乎与渲染屏幕的时间有关。当我的同事发现这一点后,他只是稍微延迟了渲染,问题就解决了。
谢谢你的帮助。
After a bit of digging around, we've been able to reliably replicate the problem. It appears to be connected to the timing of the screen being rendered. Once my collegue had identified that, he simply delayed the render slightly and that's solved the problem.
Thanks for you help.