Eine Möglichkeit wäre es, zu verfolgen, das zuvor ausgewählte Element in einer Variablen zu tun, und dann, im SelectedIndexChanged
Ereignisse, wählen Sie erneut das vorherige Element ir, wenn der Benutzer etwas wählen versucht weniger:
// Keep track of currently selected index
private int lastSelectedIndex = 0;
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DataSource = Enum.GetValues(typeof(Articlestatus));
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
// Select first item and update our tracking variable
comboBox1.SelectedIndex = 0;
lastSelectedIndex = comboBox1.SelectedIndex;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Do nothing if they re-selected the same item
if (comboBox1.SelectedIndex == lastSelectedIndex) return;
// If the newly selected item is less than the previous one, reset to previous one
if (comboBox1.SelectedIndex < lastSelectedIndex)
{
comboBox1.SelectedIndex = lastSelectedIndex;
}
else
{
lastSelectedIndex = comboBox1.SelectedIndex;
}
}
Beachten Sie, dass dieser Code für den Benutzer nicht sehr flexibel ist. Wenn sie versehentlich den falschen Gegenstand wählen, stecken sie fest. Ich stelle mir vor, dass der Code zum Aktualisieren der lastSelectedIndex
woanders hingehen sollte, wie in einem "TaskCompleted" -Ereignis, das, wenn es ausgelöst wird, bedeutet, dass sie etwas getan haben, das sie zur Auswahl verpflichtet.
Ja einige einige Details helfen. –
Sie müssen zeigen, * was * nicht funktioniert, wenn Sie Hilfe bei der Fehlerbehebung benötigen. Bitte lesen [fragen] und nehmen Sie die [Tour] – Plutonix
Mögliche Duplikat von [Erstellen Sie WinForms ComboBox mit nicht auswählbaren Elementen] (https://stackoverflow.com/questions/2290563/create-winforms-combobox-with-non-selectable- Artikel) –