C# Winform DataGridView 中如何動態插入combox


   在C# winform中,DataGridView 經常用於動態綁定數據庫中的內容,同時為了規范用戶的輸入,會將datagridview的某一列設置為combox,具體的做法如下:

  

//定義列、單元的格式,

DataGridViewComboBoxColumn dgcbc = new DataGridViewComboBoxColumn();
DataGridViewComboBoxCell it = new DataGridViewComboBoxCell();
it.Items.Add("");
it.Items.Add("Administrator");
it.Items.Add("User");
dgcbc.CellTemplate = it;

//設置列的屬性
dgcbc.DataPropertyName = "U_Right";
dgcbc.Name = "U_Right";
dgcbc.HeaderText = "U_Right";

//然后插入到datagridview中去

dataGridView1.Columns.Add(dgcbc);   

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM