0

ユーザーがアイテムを選択したときに、リストボックス(winforms 2.0)に所有者描画変数スタイルを使用しています そのセルに編集コントロールを描画したい それはドロップダウンではなく、セルまたはアイテムに表示される実際の編集コントロールですどうだった?

4

1 に答える 1

1

私はListViewに似たようなものを使用しています。方法は次のとおりです。

  1. TextBoxを作成し、Controls配列に追加して、非表示にします。

    innerTextBox.Size = new Size(0、0);

    innerTextBox.Location = new Point(0、0);

    this.Controls.AddRange(new Control [] {this.innerTextBox});

    innerTextBox.KeyPress + = new KeyPressEventHandler(this.EditOver);

    innerTextBox.LostFocus + = new EventHandler(this.FocusOver);

    innerTextBox.Hide();

    innerTextBox.Text = "";

  2. ActiveXイベントで、選択したアイテムを検索してTextBoxに値を取得する独自のメソッドをバインドします

    this.DoubleClick + = new EventHandler(this.EditableDoubleClick);

    private void EditableDoubleClick(object sender、System.EventArgs e){

    selectedItemText = selectedItem.ToString();

    innerTextBox.Size = new Size(subItemRect.right --subItemRect.left、subItemRect.bottom --subItemRect.top);

    innerTextBox.Location = new Point(subItemRect.left、subItemRect.top);

    innerTextBox.Show();

    innerTextBox.Text = selectedItemText;

    }

  3. TextBoxでフォーカスが失われた場合-選択したアイテムに値を戻します。

    selectedItem = innerTextBox.Text;

于 2009-08-03T06:36:04.613 に答える