alt text http://www.freeimagehosting.net/uploads/260c1f6706.jpg消除在C#
在數據網格的空灰色空間我如何刪除空的空間,即我想要的數據網格自動調整自身取決於沒有。的行。我知道列,我們可以通過填寫AutoSizeColumnMode值做到這一點,但對於AutoSizeRowsMode沒有填充值。
alt text http://www.freeimagehosting.net/uploads/260c1f6706.jpg消除在C#
在數據網格的空灰色空間我如何刪除空的空間,即我想要的數據網格自動調整自身取決於沒有。的行。我知道列,我們可以通過填寫AutoSizeColumnMode值做到這一點,但對於AutoSizeRowsMode沒有填充值。
一個黑客一點,但你可以試試這個:
dataGridView1.BackgroundColor = System.Drawing.SystemColors.Control;
順便說一句這已經reported as a bug。
這有效,但你仍然有邊界。任何想法如何刪除? – 2014-11-29 11:51:14
這是可以做到,你就必須一行時添加或移除來調節ClientSize。然而,它並不能完全一旦垂直滾動條出現,電網高度不是由行高度divisble隱藏背景。爲您的項目添加一個新類並粘貼下面顯示的代碼。編譯。將新的控件從工具箱的頂部拖放到表單上。
using System;
using System.Drawing;
using System.Windows.Forms;
class AutoSizeGrid : DataGridView {
private int gridHeight;
private bool resizing;
protected override void OnClientSizeChanged(EventArgs e) {
if (!resizing) gridHeight = this.ClientSize.Height;
base.OnClientSizeChanged(e);
}
protected override void OnRowsAdded(DataGridViewRowsAddedEventArgs e) {
setGridHeight();
base.OnRowsAdded(e);
}
protected override void OnRowsRemoved(DataGridViewRowsRemovedEventArgs e) {
setGridHeight();
base.OnRowsRemoved(e);
}
protected override void OnHandleCreated(EventArgs e) {
this.BeginInvoke(new MethodInvoker(setGridHeight));
base.OnHandleCreated(e);
}
private void setGridHeight() {
if (this.DesignMode || this.RowCount > 99) return;
int height = this.ColumnHeadersHeight + 2;
if (this.HorizontalScrollBar.Visible) height += SystemInformation.HorizontalScrollBarHeight;
for (int row = 0; row < this.RowCount; ++row) {
height = Math.Min(gridHeight, height + this.Rows[row].Height);
if (height >= gridHeight) break;
}
resizing = true;
this.ClientSize = new Size(this.ClientSize.Width, height);
resizing = false;
if (height < gridHeight && this.RowCount > 0) this.FirstDisplayedScrollingRowIndex = 0;
}
}
THX爲你的努力,但我得到了通過使用上述建議的方法擺脫空間。 – 2010-01-23 17:06:27
我在測試中發現了一些問題,請看:http://prnt.sc/b3rf7g我也可以刪除灰色小行嗎?根據數據,左手角落有一個很大的graw區域:http://prnt.sc/b3rft4我該如何解決這個問題? – Jack 2016-05-13 22:53:54
設置數據網格的MaxHeight
屬性。 e.g MaxHeight="150"
在我來說,我已經刪除了你在用紅色邊境以上電網已經證明的空間。
+1爲智障亮點:) – TheBlastOne 2011-09-12 14:03:34
這是「認知殘疾」的亮點。 – 2012-09-24 22:10:21