2009-04-30 119 views
0

我有一個模式窗口中的DataGridView和我的程序的選項列表。網格有兩個柱子。第一個包含用於選擇該選項的複選框,第二個是該選項的名稱/描述。該winform還包含確定和取消按鈕,但這是重點。下面的代碼做我想要的。由於FullRowSelect屬性的複選框被選中/未選中,因此您可以在該行中單擊任意位置。但它不會在當前行周圍顯示藍色背景或虛線。我將如何在不失去任何當前功能的情況下添加此功能?DataGridView:FullRowSelect和焦點

編輯:詳細說明;我想要的是再次啓用所選行/單元格上的虛線和/或藍色背景。它看起來像我現在已經莫名其妙地禁用此代碼...

有關當前代碼:

public OptionsForm() 
{ 
    InitializeComponent(); 
    OptionsRoot = Options.GetReadOnlyRoot(OptionsBannersNameValueList.GetNameValueList(Settings.Default.OptionsBanners)); 
    optionsBannersDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 
    optionsBannersDataGridView.MultiSelect = false; 
    optionsBannersDataGridView.RowPrePaint += new DataGridViewRowPrePaintEventHandler(optionsBannersDataGridView_RowPrePaint); 
    InitUI(); 
    Closing += MyFormClosing; 
    BindingSourceTree = BindingSourceHelper.InitializeBindingSourceTree(components, rootBindingSource); 
} 

private void optionsBannersDataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) 
{ 
    e.PaintParts &= ~DataGridViewPaintParts.Focus; 
} 

回答

0

我終於ened了做是去除大部分上述代碼的,因爲它確實沒有做太多。由於某些原因,當我在Visual Studio中設置屬性時,它不起作用,但現在它已經可以使用了。我不知道那裏發生了什麼,除了這一點之外。

構造函數現在看起來是這樣的:

public OptionsForm() 
    { 
     InitializeComponent(); 
     AlternativerRoot = Alternativer.GetReadOnlyRoot(AlternativerFanerNameValueList.GetNameValueList(Settings.Default.AlternativerFaner)); 
     InitUI(); 
     Closing += MyFormClosing; 
     _bindingSourceTree = BindingSourceHelper.InitializeBindingSourceTree(components, rootBindingSource); 
    } 

的屬性在Visual Studio GUI設置來代替。 SelectionMode設置爲FullRowSelect,MultiSelect設置爲false。

我仍然沒有得到我想要的焦點,所以我將所選行的背景顏色設置爲藍色,並在視覺工作室中將前景色設置爲白色。這現在就像我想要的那樣工作。

我仍然不知道爲什麼性能沒得到正確設置較早,但至少現在的工作:P

2

我會嘗試使用.OnCellClick方法和行顏色設置爲藍色。我認爲你應該也可以添加一個虛線邊框。

我相信你可以這樣調用:

optionsBannersDataGridView.OnCellClick += new DataGridViewCellEventArgs(optionsBannersDataGridView_OnCellClick); 
+0

這會確保最上面一行是加載時的藍色,但? – Sakkle 2009-04-30 09:37:56