认识的CheckedListBox已选定 [英] Recognize CheckedListBox item has been selected

查看:214
本文介绍了认识的CheckedListBox已选定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有处理checkedListBox1直到现在。 。我想打会使用它,而不是用无数的复选框中受益的程序



我的代码:

 私人无效checkedListBox1_SelectedIndexChanged(对象发件人,EventArgs五)
{
INT选择= checkedListBox1.SelectedIndex;
this.Text = checkedListBox1.Items [选择]的ToString();
}



这样做的问题是,每次我点击盒子,它突出,它则选择突出显示的对象。我所寻找的是它认识到在这个被选中,没有突出的变化。



什么,我也想知道是说,如果第一个索引项在CheckListBox检查,以及第三,我将如何检查,看看是否是真的还是假的?



我敢肯定我将最终数字出来,但看到。代码将帮助极大。



说我有3盒:
盒A = messageBox.Show(A);
箱B = messageBox.Show(B);
箱C = messageBox.Show(C);



如果选中该复选框将只显示MBOX。我想知道的是我怎么能有它检查,看看是否例如,A和C被选中,这样,如果我按一个按钮,这两个消息框将显示无论是A,然后选择C


解决方案

 私人无效checkedListBox1_ItemCheck(对象发件人,ItemCheckEventArgs E)
{
/ /一个复选框正在改变
//但价值还未被更新

}

私人无效checkedListBox1_MouseUp(对象发件人,MouseEventArgs E)
$ { b $ b的Debug.WriteLine(checkedListBox1.CheckedItems.Count);
的Debug.WriteLine(checkedListBox1.CheckedItems.Contains(checkedListBox1.Items [0]));
}



我觉得你应该检查它的MouseUp为第1是否被选中。以及_ItemCheck是当一个复选框是不断变化的,而不是更新的价值尚未



请参阅参考:的 http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.items.aspx

  //首先显示的索引并检查所有选定项目的状态。 
的foreach(在checkedListBox1.CheckedIndices的int indexChecked){
//该indexChecked变量包含项目的索引。
MessageBox.Show(指数#:+ indexChecked.ToString()+,被选中选中状态是:。+
checkedListBox1.GetItemCheckState(indexChecked)的ToString()+) ;
}

//接下来展示的对象标题和状态检查所选每个项目。
的foreach(对象checkedListBox1.CheckedItems itemChecked){

//使用IndexOf方法来获得一个项目的索引。
MessageBox.Show(标题为项:\。+ itemChecked.ToString()+
\,被选中选中状态是:+
checkedListBox1.GetItemCheckState( checkedListBox1.Items.IndexOf(itemChecked))的ToString()+)。;
}


I've never dealt with checkedListBox1 until now. A program that I want to make will benefit from using it rather than having to use numerous Checkboxes.

I have the code:

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    int selected = checkedListBox1.SelectedIndex;
    this.Text = checkedListBox1.Items[selected].ToString();
}

The problem with this is that each time I click on the box and it highlights, it then selects the highlighted object. What I am looking for is it to recognize a change in what has been selected, not highlighted.

What I'm also wanting to know is say if the first index item in CheckListBox is checked as well as the 3rd, how would I check to see if it is true or not?

I'm certain I will eventually figure it out but seeing the code would immensely help.

Say I have 3 boxes: Box A = messageBox.Show("a"); Box B = messageBox.Show("b"); Box C = messageBox.Show("c");

It will only display the mbox if the box is checked. What I want to know is how can I have it check to see if, for example, A and C is checked so that if I pressed a button, the two messageBoxes will display either "a" and then "c"

解决方案

   private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
    {
        // a checkbox is changing
        // but value is not updated yet

    }

    private void checkedListBox1_MouseUp(object sender, MouseEventArgs e)
    {
        Debug.WriteLine(checkedListBox1.CheckedItems.Count);
        Debug.WriteLine(checkedListBox1.CheckedItems.Contains(checkedListBox1.Items[0]));
    }

I think you should check it in MouseUp for whether the 1st is checked. and _ItemCheck is for when a checkbox is changing, but value not updated yet.

See reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.items.aspx

   // First show the index and check state of all selected items. 
foreach(int indexChecked in checkedListBox1.CheckedIndices) {
    // The indexChecked variable contains the index of the item.
    MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" +
                    checkedListBox1.GetItemCheckState(indexChecked).ToString() + ".");
}

// Next show the object title and check state for each item selected. 
foreach(object itemChecked in checkedListBox1.CheckedItems) {

    // Use the IndexOf method to get the index of an item.
    MessageBox.Show("Item with title: \"" + itemChecked.ToString() + 
                    "\", is checked. Checked state is: " + 
                    checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(itemChecked)).ToString() + ".");
}

这篇关于认识的CheckedListBox已选定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆