In this case you have to remove the selected Item from ComboBox1 from the other 2 Comboboxes. The same with each of the others.
But of course you also need an Init-method (or a default-Item) which sets the Item-list of each Combobox back to default ...
What is "digital" in your code-snippet ? The List of the default-Items ?
Because it isn't as trivial as I thought at the first sight here is my Code - but apologize I'm a VB-programmer. But I think you can easyly convert it to C#.
VB.Net-Version :
Dim cb_Items As String() = {"--", "X1", "X2", "X3", "X4", "X5"}
Dim cb_lastItem As String() = {"--", "--", "--"}
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ComboBox1.Items.Clear()
ComboBox1.Items.AddRange(cb_Items)
ComboBox2.Items.Clear()
ComboBox2.Items.AddRange(cb_Items)
ComboBox3.Items.Clear()
ComboBox3.Items.AddRange(cb_Items)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim sel As String = ComboBox1.SelectedItem
If sel <> cb_Items(0) Then
ComboBox2.Items.Remove(sel)
ComboBox3.Items.Remove(sel)
End If
If cb_lastItem(0) <> cb_Items(0) Then
ComboBox2.Items.Add(cb_lastItem(0))
ComboBox3.Items.Add(cb_lastItem(0))
End If
cb_lastItem(0) = sel
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim sel As String = ComboBox2.SelectedItem
If sel <> cb_Items(0) Then
ComboBox1.Items.Remove(sel)
ComboBox3.Items.Remove(sel)
End If
If cb_lastItem(1) <> cb_Items(0) Then
ComboBox2.Items.Add(cb_lastItem(1))
ComboBox3.Items.Add(cb_lastItem(1))
End If
cb_lastItem(1) = sel
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
Dim sel As String = ComboBox3.SelectedItem
If sel <> cb_Items(0) Then
ComboBox1.Items.Remove(sel)
ComboBox2.Items.Remove(sel)
End If
If cb_lastItem(2) <> cb_Items(0) Then
ComboBox1.Items.Add(cb_lastItem(2))
ComboBox2.Items.Add(cb_lastItem(2))
End If
cb_lastItem(2) = sel
End Sub
C#-Version :
private string[] cb_Items = new[] { "--", "X1", "X2", "X3", "X4", "X5" };
private string[] cb_lastItem = new[] { "--", "--", "--" };
private void Button1_Click(System.Object sender, System.EventArgs e)
{
ComboBox1.Items.Clear();
ComboBox1.Items.AddRange(cb_Items);
ComboBox2.Items.Clear();
ComboBox2.Items.AddRange(cb_Items);
ComboBox3.Items.Clear();
ComboBox3.Items.AddRange(cb_Items);
}
private void ComboBox1_SelectedIndexChanged(System.Object sender, System.EventArgs e)
{
string sel = ComboBox1.SelectedItem;
if (sel != cb_Items[0])
{
ComboBox2.Items.Remove(sel);
ComboBox3.Items.Remove(sel);
}
if (cb_lastItem[0] != cb_Items[0])
{
ComboBox2.Items.Add(cb_lastItem[0]);
ComboBox3.Items.Add(cb_lastItem[0]);
}
cb_lastItem[0] = sel;
}
private void ComboBox2_SelectedIndexChanged(System.Object sender, System.EventArgs e)
{
string sel = ComboBox2.SelectedItem;
if (sel != cb_Items[0])
{
ComboBox1.Items.Remove(sel);
ComboBox3.Items.Remove(sel);
}
if (cb_lastItem[1] != cb_Items[0])
{
ComboBox2.Items.Add(cb_lastItem[1]);
ComboBox3.Items.Add(cb_lastItem[1]);
}
cb_lastItem[1] = sel;
}
private void ComboBox3_SelectedIndexChanged(System.Object sender, System.EventArgs e)
{
string sel = ComboBox3.SelectedItem;
if (sel != cb_Items[0])
{
ComboBox1.Items.Remove(sel);
ComboBox2.Items.Remove(sel);
}
if (cb_lastItem[2] != cb_Items[0])
{
ComboBox1.Items.Add(cb_lastItem[2]);
ComboBox2.Items.Add(cb_lastItem[2]);
}
cb_lastItem[2] = sel;
}