1

値がcombox1で選択されている場合、他のすべてのコンボボックスで無効にする必要があります。たとえば、4 つのコンボ ボックスがあります。ComboBox1、ComboBox2、ComboBox3、ComboBox4. すべてが同じ値を持ちます (例: (1,2,3,4,5)) ComboBox1 で値 1 が選択されている場合、他のすべてのボックスで値 1 を無効にし、すべてのボックスで同じにする必要がありますか??? ありがとうございます。待っている。エムズマン

4

3 に答える 3

0

1stcomboBoxを使用してアイテムを選択し、他のアイテムから削除するだけでなく、コンボボックスデータソースとして汎用リストを使用する場合。拡張メソッドを使用できると思います

    /// <summary>
    /// returns a new List<T> without the List<T> which won't have the given parameter 
    ///
    /// Example Usage of the extension method :
    ///
    /// List<int> nums = new List<int>() { 1, 2, 3, 4, 5 };
    /// 
    /// List<int> i = nums.Without(3);
    /// 
    /// </summary>
    /// <typeparam name="TList"> Type of the Caller Generic List </typeparam>
    /// <typeparam name="T"> Type of the Parameter </typeparam>
    /// <param name="list"> Name of the caller list </param>
    /// <param name="item"> Generic item name which exclude from list </param>
    /// <returns>List<T> Returns a generic list </returns>

    public static TList Without<TList, T>(this TList list, T item) where TList : IList<T>, new()
        {
            TList l = new TList();

            foreach (T i in list.Where(n => !n.Equals(item)))
            {
                l.Add(i);
            }

            return l;
        }

次に、必要に応じてコンボボックスのデータソースを設定できます(リストは非常に高速です)

ちなみに、マウスによってコンボボックスのアイテムが選択されていることを確認したい場合(ユーザーアクティビティ-プログラムではありません)、SelectionChangeCommittedイベントを使用する必要があります。SelectedIndexChangedではありません。SelectedIndexChangeイベントを使用すると、コンボボックスが最初にロードされたときにもキャッチされます。ただし、SelectionChange Committedイベントは、キーボードを入力するか、コンボボックスの矢印にマウスを押して自分自身を起動するのを待ちます。

于 2012-05-25T13:28:32.540 に答える
0

次の例のように、他のコンボ ボックスから要素を削除する必要があります。

comboBox2.Items.Remove(comboBox1.SelectedItem);

ComboBox1 OnChange次のようにしてイベントを処理できます。

private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
     // remove the item in the other lists based upon ComboBox1 selection
}
于 2012-05-25T11:21:06.680 に答える
0

選択したら、他のコンボ ボックスから削除する必要があります。例えば。

//On item selected in ComboBox1
private void showSelectedButton_Click(object sender, System.EventArgs e) 
{

    comboBox2.Items.Remove(comboBox1.SelectedIndex.ToString());
    comboBox3.Items.Remove(comboBox1.SelectedIndex.ToString());
    comboBox4.Items.Remove(comboBox1.SelectedIndex.ToString());
}
于 2012-05-25T11:22:57.740 に答える