2

私はC#の初心者です。私の問題は、チェックされたアイテムをチェックリストボックスからリストボックスに追加する方法であり、このアイテムのチェックを外すと、リストボックスからも削除されます..ありがとう!

4

3 に答える 3

3

checkedListBox1ascheckedListBoxlistBoxcalledがある場合listBox1は、これを追加する必要がありItemCheck EventますcheckedListBox

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
  if (e.NewValue == CheckState.Checked)
    listBox1.Items.Add(checkedListBox1.Items[checkedListBox1.SelectedIndex]);
  if (e.NewValue == CheckState.Unchecked)
    listBox1.Items.Remove(checkedListBox1.Items[checkedListBox1.SelectedIndex]);
}
于 2012-09-26T18:38:48.453 に答える
1

アイテムを追加:

YourListbox.Items.Add("");

リンク: http://msdn.microsoft.com/fr-fr/library/system.windows.forms.listbox.objectcollection.add.aspx

アイテムを削除:

YourListbox.Items.Remove("");

リンク: http://msdn.microsoft.com/fr-fr/library/system.windows.forms.listbox.objectcollection.remove.aspx

var items = new System.Collections.ArrayList(listboxFiles.SelectedItems);

foreach (var item in items) {
        listbox.Items.remove(item);

}
于 2012-09-26T17:59:23.300 に答える
0

ASPX

<asp:CheckBoxList ID="_CheckBoxList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="CheckBoxList_SelectedIndexChanged">
    <asp:ListItem Text="1" Value="1"></asp:ListItem>
    <asp:ListItem Text="2" Value="2"></asp:ListItem>
</asp:CheckBoxList>
<asp:ListBox ID="_ListBox" runat="server"></asp:ListBox>

CS

protected void CheckBoxList_SelectedIndexChanged(object sender, EventArgs e)
{
    CheckBoxList cbx = (CheckBoxList)sender;

    _ListBox.Items.Clear();
    foreach (ListItem item in cbx.Items)
    {
        if(item.Selected)
            _ListBox.Items.Add(new ListItem(item.Text, item.Value));
    }

}

AJAX を使用するには、更新パネルにラップします

于 2012-09-26T18:19:01.133 に答える