2017-10-23 3 views
-2

私はwinformでコンボボックスを持っています。列挙型にバインドされています。 enumは、記事のステータスをオーダーで表示します。私は、ユーザーが注文に従い、更新された場合にユーザーが以前のステータスを選択することを制限します。私はselectedIndexchangedイベントを試しましたが、それは動作しませんでした。それが少ないものを選択するために、変数に以前に選択した項目を追跡し、その後、SelectedIndexChangedイベントでは、ユーザーがしようとした場合のIR前の項目を再選択することです行うにはComboboxの以前のインデックスで値を選択できないようにユーザーを制限します。winform

public enum Articlestatus : Byte 
    { 
     Inplagiarism = 0, 
     Consentletter = 1, 
     Inreview = 2, 
     AuthorRevision = 4, 
     ReReview = 8, 
     Reject = 16, 
     Accept = 32, 
     Published = 64 
    } 
+0

はいいくつかの詳細が役立ちます。 –

+1

あなたがそれを修正するのを助けたい場合は、*何* didntの作品を表示する必要があります。 [ask]を読んで[ツアー]を受けてください – Plutonix

+1

[選択できない項目でWinFormsコンボボックスを作成する]の複製があります(https://stackoverflow.com/questions/2290563/create-winforms-combobox-with-non-selectable-アイテム) –

答えて

0

一つの方法:

// 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; 
    } 
} 

このコードは、ユーザーにとってあまりフレキシブルではありません。誤って間違ったアイテムを選択した場合、そのアイテムはスタックされています。 lastSelectedIndexを更新するコードは、「TaskCompleted」イベントのように、別の場所に移動する必要があります。このイベントは、起動すると、選択肢にコミットする何かを行ったことを示します。

+0

thats問題です。基本的に、私はcellclickイベントのgridviewから対処している値があり、既定では以前の値がある記事もあります。それ以外の場合は動作します。 –

関連する問題