hello every one ;
Q. how we can perform addition of integers in list box ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sumaira manzoor hussain khanPosted Aug 6, 2010, 1:54 AM
now this is a final code for additing integers in list box .
private void button1_Click(object sender, System.EventArgs e)
{
int a=0, b = 0,c=0;
for (a=0; a < listBox1.Items.Count;a++)
{
b += Convert.ToInt32(listBox1.Items[a]);
c = c+b;
b = 0;
}
label1.Text = Convert.ToString(c);
}
theLizardPosted Aug 6, 2010, 1:38 AM
b += int.TryParse(listBox1.Items.Add(a));
you are attempting to add an int to the listbox and then get a total, not possible.
.value My mistake should be
b += int.TryParse(lb.Items[i].ToString());
theLizardPosted Aug 6, 2010, 1:37 AM
b += int.TryParse(listBox1.Items.Add(a));
you are attempting to add an int to the listbox and then get a total, not possible.
.value My mistake should be
b += int.TryParse(lb.Items[i].ToString());
theLizardPosted Aug 6, 2010, 1:37 AM
b += int.TryParse(listBox1.Items.Add(a));
you are attempting to add an int to the listbox and then get a total, not possible.
.value My mistake should be
b += int.TryParse(lb.Items[i].ToString());
sumaira manzoor hussain khanPosted Aug 6, 2010, 1:14 AM
i wrote your code . but your code is given error.
for (a=0; a < listBox1.Items.Count;a++)
{
b += int.TryParse(listBox1.Items.Add(a));
}
i tell you one thing. " .value " does not exist in listbox library .
theLizardPosted Aug 6, 2010, 12:53 AM
if you want to total the integers moved to the second list box 2 then this total += TryInt.Parse(ListBox->Items[i].value); becomes this total += TryInt.Parse(ListBox2->Items[i].value);
sumaira manzoor hussain khanPosted Aug 6, 2010, 12:45 AM
my requirement is :
i added many integers in checkedlist box through this code :
code of add integers in list box :
this.checkedListBox1.Items.Add("3");
this.checkedListBox1.Items.Add("85");
this.checkedListBox1.Items.Add("3500");
after this code i used listbox in my form .after this i selected integers like 3 , 3500 etc randomly and move in second list box. my desire integers will be moved from checkedlistbox to listbox. so, the desire integers has been come in list box. i want to perform addition between these integers that are exit in my list box.
theLizardPosted Aug 5, 2010, 11:27 PM
int total = 0;
for(int i = 0; i < ListBox.Items.Count; i ++)
{
total += TryInt.Parse(ListBox->Items[i].value);
}
you may have to do error checking to make sure that the list box value can be converted to an integer.
I have not tried this but it is basically one correct way of doing it.
Sam HobbsPosted Aug 5, 2010, 5:44 PM
Tanmay SarkarPosted Aug 5, 2010, 1:27 PM
please clear it.
What you want to do?
You have 2 value in a list & want to add & show it on that list box?
or you have 2 list box chose integer & want to add.
or you want anything else.
Please clear it first. :)