DataGridView set column cell Combobox

后端 未结 8 2085
滥情空心
滥情空心 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:01

    You could try the following:

    DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();
    column.Name = "Money";
    column.DataSource = new string[] { "10", "30", "80", "100" };
    dataGridView1.Columns.Add(column);
    
    for (int row = 0; row < dataGridView1.Columns.Count; row++)
    {
       DataGridViewComboBoxCell cell = 
           (DataGridViewComboBoxCell)(dataGridView1.Rows[row].Cells["Money"]);
       cell.DataSource = new string[] { "80", "100" };
    }
    

    Or this:

    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(row.Cells["Money"]);
        cell.DataSource = new string[] { "10", "30" };
    }
    

提交回复
热议问题