ListView列上的平均数 [英] Average number on ListView column

查看:76
本文介绍了ListView列上的平均数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有人可以帮我解决以下问题吗?

如何从ListView1.Items(ListView1.Items.Count - 1).SubItems.Add((reader("High").ToString) - (reader("Low").ToString))列中获得AVERAGE编号,并在标签上显示AVERAGE编号.


Hi,

Is somebody can help me with the following question?

How can I get the AVERAGE number from the column of ListView1.Items(ListView1.Items.Count - 1).SubItems.Add((reader("High").ToString) - (reader("Low").ToString)) and shows the AVERAGE number on the label.


Dim Cmd As SqlCommand = New SqlCommand(SelectCmd, conn)
Dim reader As SqlDataReader
reader = Cmd.ExecuteReader()

''**************************
Do While (reader.Read())

ListView1.Items.Add(reader("Id").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(reade("Date").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(reade("High").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(reader("Low").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add((reader("High").ToString) - (reader("Low").ToString))

Loop
''***************************
 reader.Close()
 conn.Close()


例如:
列的输出将是:
1
3
5
2
8
________
平均:3.8

那就是我想要在标签上标明的数字.

谢谢您的帮助!


For example:
The column outputs will be:
1
3
5
2
8
________
Avg: 3.8

That will be the number i would like to have it on the label.

Thank you for your help!

推荐答案

这确实不是那么困难.我肯定希望您刚刚开始,并且实际上是在上课的人中.

您需要从逻辑上考虑问题.您需要做什么来解决它?

好吧,您需要遍历ListView中的每个项目并总结其值.

然后,将该值除以项目总数,对吗?您到底不清楚什么?

This really isn''t that difficult. I sure hope you''re just starting out and actually in a class doing this.

You need to think through the problem logically. What do you need to do to solve it?

Well, you need to go through each item in the ListView and sum up their values.

Then, divide that value by the total number of items, right? What exactly are you unclear about?

Dim sum as Long = 0

For Each lvItem as ListViewItem in ListView1.Items
  sum += CInt(item.SubItems(0).Text)
Next

Label1.Text = sum / ListView1.Items.Count



如果您不能理解那么简单的内容,也许这不是您的专业.



If you can''t understand something as simple as that, maybe this isn''t the profession for you.


ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(((reader(High)- (reader(Low)) / 2).ToString))


怎么样
或者,您也可以发布SQL并在查询中添加一个新字段.



Or you could also post your SQL and have a new field added to the query.


这篇关于ListView列上的平均数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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