2017-01-02 21 views
2

我已經創建了自定義DataGridViewSliderColumn類,它在單元格內呈現一個TrackBar。贏取表單DatagridView。如何從設計師添加自定義列?

我的問題是,我如何設置列的類型爲我的自定義DataGridViewSliderColumn在設計器中? (我在設計師中定義了很多專欄)。

我試過了,但只有預定義的列類型出現在設計器上。

是否可以設置它,而不必在運行時通過代碼更改列定義?

回答

0

簡單的回答:創建自定義列類後,重新構建您的項目。


例如,假設我們已經創建了一個名爲custom Watermark columnDataGridViewWatermarkColumn。若要將其添加到設計選項,因此在DataGridView,請執行下列操作:

  1. 重新生成解決方案,一旦自定義列門類齊全。
  2. 在設計人員DataGridView中,單擊右上角的箭頭以展開DataGridView Tasks

    An arrow to expand DataGridView Tasks.

  3. 選擇Add Column...

    The DataGridView Tasks popup for Columns and permissions.

  4. 在添加列對話框中,選擇Type -> YourCustomColumn,然後單擊Add

    Add Column dialog showing the custom column added to the Type ComboBox options.

就是這樣。做任何必要的編輯(例如在本例中設置Column.WatermarkText),運行它並享受。

Final result displaying a DataGridView with a custom watermark column and a normal TextBox column.

相關問題