Hallo Experten,
ich habe ein DataGridView, das auch DataGridViewComboBoxColumns enthält. Die werden so erstellt:[highlight="c#"]
public enum MyEnum
{
None,
First,
Second,
Third,
Fourth,
Fifth
}
for(int comboColumnIndex = 0; comboColumnIndex < comboColumnCount; comboColumnIndex++)
{
int columnIndex = myDataGridView.Columns.Add(new DataGridViewComboBoxColumn());
myDataGridView.Columns[columnIndex].Name = "Combo" + comboColumnIndex.ToString();
((DataGridViewComboBoxColumn)(myDataGridView.Colum ns[columnIndex])).DataSource = Enum.GetValues(typeof(MyEnum));
}
[/highlight]Später werden dann Zeilen erzeugt[highlight="c#"]
for (int i = 0; i < 10; i++)
{
int rowIndex = myDataGridView.Rows.Add();
myDataGridView.Rows[rowIndex].HeaderCell.Value = (i + 1).ToString();
for (int comboColumnIndex = 0; comboColumnIndex < _comboColumnCount; comboColumnIndex++)
myDataGridView.Rows[rowIndex].Cells["Combo" + comboColumnIndex.ToString()].Value = MyEnum.None;
}[/highlight]
Fürs Erste scheint das zu funktionieren. Aber nur solange, bis der Benutzer einen ComboBox-Wert geändert hat. Von da an mündet jedes Neuzeichnen der Zelle in einer Fehlermeldung
Wie mache ich es richtig, Spalten zu erzeugen, deren Zellen Comboboxen mit den Auswahlmöglichkeiten aus MyEnum sind?
Ich sag schonmal Danke im Voraus,
luker
ich habe ein DataGridView, das auch DataGridViewComboBoxColumns enthält. Die werden so erstellt:[highlight="c#"]
public enum MyEnum
{
None,
First,
Second,
Third,
Fourth,
Fifth
}
for(int comboColumnIndex = 0; comboColumnIndex < comboColumnCount; comboColumnIndex++)
{
int columnIndex = myDataGridView.Columns.Add(new DataGridViewComboBoxColumn());
myDataGridView.Columns[columnIndex].Name = "Combo" + comboColumnIndex.ToString();
((DataGridViewComboBoxColumn)(myDataGridView.Colum ns[columnIndex])).DataSource = Enum.GetValues(typeof(MyEnum));
}
[/highlight]Später werden dann Zeilen erzeugt[highlight="c#"]
for (int i = 0; i < 10; i++)
{
int rowIndex = myDataGridView.Rows.Add();
myDataGridView.Rows[rowIndex].HeaderCell.Value = (i + 1).ToString();
for (int comboColumnIndex = 0; comboColumnIndex < _comboColumnCount; comboColumnIndex++)
myDataGridView.Rows[rowIndex].Cells["Combo" + comboColumnIndex.ToString()].Value = MyEnum.None;
}[/highlight]
Fürs Erste scheint das zu funktionieren. Aber nur solange, bis der Benutzer einen ComboBox-Wert geändert hat. Von da an mündet jedes Neuzeichnen der Zelle in einer Fehlermeldung
DataGridView-Ausnahme:
System.ArgumentException: der DataGridViewComboBoxCell-Wert ist ungültig.
Behandeln Sie das DataError-Ereignis, um dieses Standarddialogfeld zu ersetzen.
System.ArgumentException: der DataGridViewComboBoxCell-Wert ist ungültig.
Behandeln Sie das DataError-Ereignis, um dieses Standarddialogfeld zu ersetzen.
Ich sag schonmal Danke im Voraus,
luker
Comment