DataGridView set column cell Combobox

后端 未结 8 2093
滥情空心
滥情空心 2020-12-05 19:36

I have tables like that in Datagridview:

 Name   Money
 -------------
 Hi      100   //here Combobox with member {10,30,80,100} to choose
 Ki      30    //he         


        
8条回答
  •  鱼传尺愫
    2020-12-05 20:05

    You were almost done.

    There are only two minor issues:

    1. In your table you are adding to rows "Money" value as integers, while in your column they are defined as string
    2. First add your table ad DataGridView DataSource, and then set column DataPropertyName

    Full code below:

    var table = new DataTable();
    table.Columns.Add("Name", typeof(string));
    table.Columns.Add("Money", typeof(string));
    table.Rows.Add("Hi", "100");
    table.Rows.Add("Ki", "30");
    
    var column = new DataGridViewComboBoxColumn();
    column.DataSource = new List() { "10", "30", "80", "100" };            
    
    dataGridView1.Columns.Add(column);
    dataGridView1.DataSource = table;
    

提交回复
热议问题