2009-12-31 48 views
2

我創建了一個自定義DataGridViewCell,用於在用戶開始編輯單元格時顯示特定的UserControl。基本上控制包含一個TextBox與代碼輕鬆處理的建議列表。
我得到我的代碼來正確調整列表的大小,並讓它包含我想要的以及我想要的位置。我現在遇到的問題是,屏幕上的控件沒有正確繪製,並且ListBox可能是在該行的「內部」繪製的,並且由於它比該行高很多,所以不會在屏幕上顯示。在自定義DataGridViewCell中承載UserControl

如何在DataGridView的頂部製作控件?

回答

2

您可能需要將ListBox放在單獨的彈出窗體中。祝你好運。

或者,您可以將ListBox放在GridView的父窗體中,然後調用BringToTop以確保它位於網格視圖的頂部。

0

我想你會想看看Faking alternative controls within a DataGridView control in Win Forms 2.0。它會外觀就像控件託管在DataGridView中,但實際上它恰好位於單元格上。我現在使用這兩個DateTimePickers和一個組合框取得了巨大的成功。從鏈接

示例代碼:

protected void dgCategory_CellClick(object sender, DataGridViewCellEventArgs e) 

{ 

//set Date Picker to false when initially click on cell 

     if (dtPicker.Visible) 
      dtPicker.Visible = false; 
     if (e.ColumnIndex == 2) 
     { 
     //set date picker for category datagrid 
     dtPicker.Size = dgCategory.CurrentCell.Size; 
     dtPicker.Top = dgCategory.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Top; 
     dtPicker.Left = dgCategory.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Left; 

     if (!(object.Equals(Convert.ToString(dgCategory.CurrentCell.Value), ""))) 
      dtPicker.Value = Convert.ToDateTime(dgCategory.CurrentCell.Value); 
     dtPicker.Visible = true; 

     } 
} 

private void dtPicker_ValueChanged(object sender, EventArgs e) 
{ 
     dgCategory.CurrentCell.Value = dtPicker.Value; 
     dtPicker.Visible = false; 

} 
相關問題