gpt4 book ai didi

vb.net - 从 Datagridview 列获取最小值

转载 作者:行者123 更新时间:2023-12-02 06:30:07 25 4
gpt4 key购买 nike

我想从我的 datagridview 列中获取最低值!

我的datagridview的名称是datagridview1

这是我的数据 GridView :

|-Number-|

|---90---|

|---70---|

|---20---|

|---80---|

|---50---|

|---60---|

我一直在尝试一些代码:

Dim MinVal As Double = 99999999

For Each row As DataGridViewRow In DataGridView1.Rows

If row.Cells(0).Value < MinVal Then MinVal = row.Cells(0).Value

Next

TextBox9.Text = MinVal

没有错误。但结果是60而不是20

发生了什么?请帮助我!

最佳答案

    Dim Max As Integer = 0

For Each rws As DataGridViewRow In DataGridView1.Rows
If Max < rws.Cells(0).Value Then Max = rws.Cells(0).Value
Next

'Maximum Value
Msgbox(Max)

对于最小值,您必须使用该最大值

    Dim Min As Integer = Max

For Each rws As DataGridViewRow In DataGridView1.Rows
If Min > rws.Cells(0).Value Then Min = rws.Cells(0).Value
Next

'Minimum Value
Msgbox(Min)

关于vb.net - 从 Datagridview 列获取最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20299567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com