基于visual studio 2010中的列表框的问题 [英] Question based on listbox in visual studio 2010

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

问题描述

我在列表框中输入了候选人姓名。候选名称的数量应该是未知的。当选择名称时,必须为该候选人投票,并且只能投一个名人。最后,当投票程序完成后,结果必须显示在条形图中



我尝试了什么:



我已经尝试了

i have the candidate names entered in a listbox. The number of candidate names are supposed to be unknown. when the name is selected a vote must be cast for that candidate, and only one vast can be cast. finally when the voting procedure is complete the results must be displayed in a barchart

What I have tried:

ive tried

Dim vote As Integer = 0
Dim count As Integer
For count = 0 To ListBox1.Items.Count = 1
    If ListBox1.SelectedIndex = 0 Then
        vote = vote + 1
    ElseIf ListBox1.SelectedIndex = 1 Then
        vote = vote + 1
    ElseIf ListBox1.SelectedIndex = ListBox1.Items(count) Then
        vote = vote + 1



我确定我走错了方向但是有人可以帮助我


im sure ive gone the wrong way but can someone kindly help me

推荐答案

停止你的意思正在做,并再次阅读这个问题。

要求你做的不是增加投票数,而是增加对特定候选人的投票,并阻止你投票不止一次。

这意味着您需要存储某个地方 - 或者可能存在候选类别的现有字段 - 这样您就可以计算该候选人的投票数。



首先手工试用,然后在跳入代码之前准确计算出你必须做的事情 - 否则你最终会产生一些无关紧要的东西你已经设定的任务!试一试:为每位候选人设置一张纸,并准确了解您要完成任务所需做的事情。那么将它转换为基于计算机的表格需要做的很明显。
Stop what you are doing, and read the question again.
What it is asking you to do is not increment a count of "votes cast" but to add a vote to a specific candidate, and to prevent you from voting more than once.
That means that you need to store somewhere - or possibly there is an existing field with your Candidate class - that allows you to count the votes for that candidate.

Try it on paper first by hand and work out exactly what you have to do before you leap into code - otherwise you will end up producing something that bears no relation to the task you have been set! Try it: set up a sheet of paper for each candidate, and see exactly what you have to do to fulfil the task. It should then be fairly obvious what you need to do to convert that to a computer based form.


这篇关于基于visual studio 2010中的列表框的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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