0

datagridview コンボ ボックスで値を選択しようとしていますが、すべてのグーグル検索から、次のように動作するはずですが、そうではありません。ドロップダウン メニューが最初は空白であるという問題。その後、値を手動で選択でき、コードによって保存されますが、復元しようとすると、コンボ ボックスの値が空白になります。テスト目的で、手動で値を「tag1」に設定しようとしていますが、それでも機能しません。

DataGridViewComboBoxColumn DropMenu = new DataGridViewComboBoxColumn();
DropMenu.Name = "Tag";
// getListState returns a list of strings
DropMenu.DataSource = SettingsSingelton.Instance.getListState();
DropMenu.ValueType = typeof(string); ;            

dataGridView1.Columns.Add(DropMenu);

for (int i = 0; i < dataGridView1.RowCount && i < storage.Count; i++)
{
  DataGridViewComboBoxCell cell = dataGridView1[3, i] as DataGridViewComboBoxCell;
  if (storage[i].tag != null || storage[i].tag != string.Empty)
  {
    cell.Value = "tag1";
  }
}
4

1 に答える 1

1

CellFormatting イベントを処理する必要があります。

private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
      if (e.ColumnIndex == 0) 
      {
          e.Value = "Default_Value";
      }
}
于 2012-01-13T22:44:23.637 に答える