0

私のwinformsアプリケーションでは、DataGridView1つの行がDataGridViewComboBoxColumnコントロールを使用して、この列のコンボボックスが含まれる場所があります。

その列のコンボボックスの一部をプログラムで別のものに置き換えることは可能ですか?(たとえば、「n / a」というラベル)。特定の行にのみコンボボックスが必要です。

4

1 に答える 1

2

DataGridViewComboBoxCellプロパティの代わりにプロパティを使用する必要がありDataGridViewComboBoxColumnます。以下のようなもの:

for(int intCount=0;intCount<dgv.Rows.Count;intCount++)
{
   if(intCount % 2 == 0)  //Your own condition here
   {
      DataGridViewComboBoxCell cmb = new DataGridViewComboBoxCell();
      //cmb.Value   // assign values in the combobox
      dgv[0,intCount] = cmb;
   }
   else
   {
      DataGridViewTextBoxCell txt = new DataGridViewTextBoxCell();
      txt.Value = "n/a";
      dgv[0,intCount] = txt;
   }
}

上記の例では、最初の列に個別のセルのプロパティを割り当てています。

于 2012-12-08T11:39:31.047 に答える