我有我的DataGrid Windows窗體上,我在運行時添加一行到數據網格。我有一個DataGrid的列,我需要在運行時添加不同的UI控件(列的每個單元格將包含不同的UI控件,如下拉列表,複選框,超鏈接,單選按鈕)。我可以添加除單選按鈕控件之外的其他控件,如何將單選按鈕添加到DataGrid列? 我已經使用this它不適合我,因爲它需要整列作爲單選按鈕列。
3
A
回答
0
在這裏,如何使複選框的列作爲RadioButtons工作。從你的圖片你需要一個所有的列作爲RadioBUttons - >這是更復雜,並取決於你的綁定數據datagridview。我的工作多與VB.NET所以這裏可能有些語法錯誤...
在你的datagridview 創建DataGridViewCheckBoxColumn柱DataGridView中的三個事件我複選框列的工作作爲一個單選按鈕
private Boolean bRbtnCurrentValue
private Int32 iColumnRadioBtn = 4
private Datagridview dgv //Only for this exapmle
//In Event dgv_CellBeginEdit
{
//Here we stored current value to variable
if (this.dgv.CurrentCell.ColumnIndex = this.iColumnRadioBtn)
this.bRbtnCurrentValue = this.dgv
}
//In Event dgv_CellEndEdit
{
//Here we update if value changed
Boolean bNewValue = this.dgv.CurrentCell.Value
if (this.dgv.CurrentCell.ColumnIndex = this.iColumnRadioBtn)
{
if(bNewValue=False)
this.dgv.CurrentCell.Value=this.bRbtnCurrentValue
else
//Here jo actions when value changed(database update etc.)
}
}
//Event dgv_ CurrentCellDirtyStateChanged
{
if(this.dgv.CurrentCell.ColumnIndex = this.iColumnRadioBtn) andalso (dgv.IsCurrentCellDirty = True)
{
foreach(DataGridViewRow dgvr In dgv.Rows)
{
If (dgvr.Index = dgv.CurrentRow.Index)
If (dgv.CurrentCell.Value = True)
dgv.CancelEdit() //True to False cannot be changed
else
If (dgvr.Cells(dgv.CurrentCell.ColumnIndex).Value=True)
dgvr.Cells(dgv.CurrentCell.ColumnIndex).Value = False
}
}
}
+0
正如你告訴我應該ceate DataGridViewCheckBoxColumn,但在我的應用程序列中還可以包含cotrols像組合,文本框和超鏈接。所以我不能添加DataGridViewCheckBoxColumn,我想添加不同的控制列的每個單元格。 – nirav
相關問題
- 1. C#添加WPF按鈕到Windows窗體
- 2. 如何在Windows窗體中動態添加單選按鈕?
- 3. 在web2py中添加單選按鈕到自定義窗體
- 4. 將Web窗體控件添加到Windows窗體
- 5. 如何將許多控件添加到Windows窗體選項卡?
- 6. Windows窗體單選按鈕單擊事件正在啓動
- 7. 將按鈕添加到窗體的控制框?
- 8. 動態移除/添加Windows窗體窗體上的控件
- 9. 在Windows窗體窗體上動態添加控件
- 10. 在datagrid視圖控件的當前單元格中添加按鈕控件
- 11. 帶單選按鈕的JQuery窗體控件
- 12. 將事件添加到Windows窗體中的用戶控件
- 13. Rails簡單窗體Bootstrap單選按鈕
- 14. Windows窗體:帶菜單的按鈕
- 15. Windows窗體控件設計器,添加'任務菜單'
- 16. 將屬性添加到窗體控件
- 17. 無法將控件添加到窗體
- 18. WPF:將按鈕列添加到Datagrid
- 19. 將onclick事件添加到動態添加的單選按鈕
- 20. 如何將動態按鈕及其事件添加到Windows窗體?
- 21. 如何使用C#將瀏覽文件按鈕添加到Windows窗體#
- 22. 拖放Windows窗體按鈕
- 23. Windows窗體按鈕在C#
- 24. Windows窗體 - 點擊按鈕
- 25. 如何將xaml頁面/ usercontrol添加到Windows窗體控件?
- 26. 將用戶控件添加到Windows窗體c時出錯#
- 27. 在Windows窗體中添加用戶控件(WPF)到面板c#
- 28. 如何將數據從datagrid視圖加載到按鈕單擊事件上的單獨窗口窗體?
- 29. 添加單選按鈕
- 30. 將單選按鈕添加到Tkinter
什麼使用它的目的?使用Radiobutton時,只有一些選項可供選擇。如果你只希望每行使用它,你應該使用複選框 – MVCKarl
如果只有一個選項可供選擇,我會建議使用複選框。 – Rauld
我已經通過添加圖片更新了問題,這就是我在網格中需要的。 – nirav