选中的列表框已选中/未选中 [英] Checked List Boxes Checked/Unchecked

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

问题描述

大家好,

我正在尝试开发披萨点菜系统.我对使用检查列表框"感到困惑.我有一个选中的列表框和5个项目.该软件有望做到这一点;当用户单击item1时,未单击item1时,总奖金应增加+ 0.5,然后总奖金应返回实际值.等等.

totalprize = 10;
item1已检查= 10.50
item1未选中= 10.00
item2已检查= 10.75
item2未选中= 10.00
项目1和项目2都被选中= 11.25,依此类推.

我需要有关复选框列表框的属性和此部分的逻辑(如果为else结构)的帮助.

快照:
程序快照 [

Hello everyone,

I am trying to develop an Pizza Ordering System. I am confused about using Checked List Boxes. I have a checked list box and 5 items. The software is expected to do this; when user clicked an item1, the total prize should increse + 0.5 when item1 is unclicked then the total prize should return the actual value. and so on.

totalprize = 10;
item1 checked = 10.50
item1 is unchecked = 10.00
item2 is checked = 10.75
item2 is unchecked = 10.00
both item1 and item2 is checked = 11.25 and so on.

I want help about the property of checked list box and logic (the if else structure) of this part.

Snapshot:
Snapshot Of Program[^]

Code I am confused:(Completely Wrong, not calculating)

private void checkedListBoxAdditions_ItemCheck(object sender, ItemCheckEventArgs e)
{
    if (checkedListBoxAdditions.GetItemChecked(checkedListBoxAdditions.SelectedIndex))
    {
        txtTotalAmount.Text = Convert.ToString(price[4] + double.Parse(txtTotalAmount.Text));
    }
    else
    {
        txtTotalAmount.Text = Convert.ToString( double.Parse(txtTotalAmount.Text) - price[4] );
    }
    //if (checkedListBoxAdditions.GetItemChecked(checkedListBoxAdditions.Items.IndexOf("Domato")))
    //{
    //    txtTotalAmount.Text = Convert.ToString(price[5] + double.Parse(txtTotalAmount.Text));
    //}
    //else
    //{
    //    txtTotalAmount.Text = Convert.ToString(double.Parse(txtTotalAmount.Text) - price[5]);
    //}
}



谢谢您的考虑.
T.E



Thanks For your considerations.
T.E

推荐答案

代替使用CheckedListBox,您可以使用5个复选框,这将使您的生活更轻松.见下文-

添加5个复选框,例如c1,c2,c3,c4,c5,并添加CheckedCHanged事件的事件处理程序

Instead of using CheckedListBox, you could have used 5 checkboxes and that would have made your life easier. See below -

Add 5 checkboxes say c1,c2,c3,c4,c5 and add event handlers for CheckedCHanged Event

private void c1_CheckedChanged(Object sender, EventArgs e) {
   if(c1.Checked)  
     txtTotalAmount.Text = double.Parse(txtTotalAmount.Text)) + 0.5;
   else
     txtTotalAmount.Text = double.Parse(txtTotalAmount.Text)) - 0.5;
}



更改要在每个复选框事件中添加/减去的数量,这可以解决您要查找的内容.



Change the amount you want to add/subtract in each checkbox event and this solves what you are looking for.


这篇关于选中的列表框已选中/未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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