家庭视觉工作室2010从C#windows RJ raj RJ raj 0117中的checklistbox中添加所选项目的价格从C#windows中的checklistbox中添加所选项目的价格 [英] Home visual studio 2010 add price of selected items from checklistbox in C# windows RJ raj RJ raj 0117 add price of selected items from checklistbox in C# windows

查看:66
本文介绍了家庭视觉工作室2010从C#windows RJ raj RJ raj 0117中的checklistbox中添加所选项目的价格从C#windows中的checklistbox中添加所选项目的价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Plz帮助我!



我正在开发一个VS 2010 C#windows窗体应用程序,这样当我从combobox选择课程然后复选框时,我有一个带有主题名称的checkedlistbox显示与课程名称相关的所有科目。我也有简单的复选框(选择所有主题),我想检查所有主题或检查特定主题。现在,当我检查主题时,将添加费用并显示在文本框中。费用列入主题表数据库



例如:

主题名称=费用

Checkedlistbox项目1英语= 1000

Checkedlistbox项目2印地语= 500

Checkedlistbox项目3 Marathi = 800

Checkedlistbox项目4 Science = 2000

Checkedlistbox项目....... n



在选定的主题事件上,如果我检查了项目1,2和4,我想要textbox1中显示的这些值的总和(即3500)



非常感谢。



我尝试过的方法:



Plz help me!

I am developing a VS 2010 C# windows form application such that I have a checkedlistbox with subject name when i choose course from combobox then checkboxlist shows all subject related to course name. also I have simple checkbox for (select all subject), i want to check all subject or check particular subject . Now when i checked subject then fee will be added and show on textbox . fee is given into the database of subject table

For example:
Subject Name= Fee
Checkedlistbox item 1 English= 1000
Checkedlistbox item 2 Hindi = 500
Checkedlistbox item 3 Marathi = 800
Checkedlistbox item 4 Science= 2000
Checkedlistbox item .......n

On a subject selected event, If for instance I checked items 1,2 and 4, I want the sum of these values (i.e 3500)
displayed in textbox1.
Many thanks.

What I have tried:

private void chkselectsubject_CheckedChanged(object sender, EventArgs e)
        {            
            if (chkselectsubject.Checked)
            {               

                for (int i = 0; i < chklbselectsubject.Items.Count; i++)
                {
                    chklbselectsubject.SetItemChecked(i, true);
                   
                }              
            }
            else
            {
                for (int i = 0; i < chklbselectsubject.Items.Count; i++)
                {
                    chklbselectsubject.SetItemChecked(i, false);
                
                }
            }

推荐答案

您可以迭代存储在里面的List

You could iterate though the List that is made to store inside the
List<string> subjects = new List<string>();
            foreach (var item in chekBox.Items) {
                subjects.Add(item.ToString());
            }

           
   string sqlcommand = "Select * from tblSubjectRates where subjectName=@SubjectName";
            List<int> SubjectRates = new List<int>();
            using (SqlConnection con = new SqlConnection(connectionString)) {
                con.Open();
                using (SqlCommand cmd = new SqlCommand(sqlcommand, con)) {
                    foreach (var item in subjects) {
                        cmd.Parameters.AddWithValue("@SubjectName", item.ToString());
                        var x = cmd.ExecuteScalar();
                        SubjectRates.Add(Convert.ToInt32(x));
                    }                 
                    
                }
                int TotalSum = SubjectRates.Sum();
            }





我不知道它是否会起作用......但试一试。

我试图在脑海里生成它,因为我不知道你的数据库架构,以便完全帮助你。只需替换您认为会产生错误的关键字,我希望这个逻辑能够正常工作!

最好的愿望和手指交叉!



I dont know if it will work... but give it a try.
I tried to generate it in my mind since i do not know your database schema in order to fully help you out. Just replace the keywords you think that will generate an error and i hope that this logic will work!
Best wishes and fingers crossed!


这篇关于家庭视觉工作室2010从C#windows RJ raj RJ raj 0117中的checklistbox中添加所选项目的价格从C#windows中的checklistbox中添加所选项目的价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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