Hi Guys,
I am new at c sharp and I would like to know how I can find a min and max value in a listBox.
lets say I have a listbox which gets the elements from a text box and by a btn click events like this:
int intItems = (int)Convert.ToInt32(txtInput.Text);
listBox1.Items.Add(intItems);
I know how to get count and sum and average of these elements
could you please let me know how I can find these values(Max, Min)?
Regards
I am new at c sharp and I would like to know how I can find a min and max value in a listBox.
lets say I have a listbox which gets the elements from a text box and by a btn click events like this:
int intItems = (int)Convert.ToInt32(txtInput.Text);
listBox1.Items.Add(intItems);
I know how to get count and sum and average of these elements
could you please let me know how I can find these values(Max, Min)?
Regards


Marimuthu ArigovindasamyRank #5,893 · 283 reputationPosted Jun 18, 2010, 12:20 AM EDT
int minValue = 0;
int maxValue = 0;
if (listBox1.Items.Count > 0)
{
minValue = Convert.ToInt32(listBox1.Items[0]);
maxValue = Convert.ToInt32(listBox1.Items[0]);
}
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (minValue > Convert.ToInt32(listBox1.Items[i]))
{
minValue = Convert.ToInt32(listBox1.Items[i]);
}
if (maxValue < Convert.ToInt32(listBox1.Items[i]))
{
maxValue = Convert.ToInt32(listBox1.Items[i]);
}
}
Behrouz Hosseini64 reputationPosted Jun 18, 2010, 12:52 AM EDT
It is working now I really appreciate.
Marimuthu ArigovindasamyRank #5,893 · 283 reputationPosted Jun 18, 2010, 1:01 AM EDT
meng24 reputationPosted Sep 28, 2012, 12:18 PM EDT
thanks
VulpesRank #55 · 29.2K reputationPosted Sep 28, 2012, 12:34 PM EDT
meng24 reputationPosted Sep 28, 2012, 12:59 PM EDT