vb.net 从 Datagridview 列中获取最小值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20299567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Minimum Value From Datagridview Column
提问by Gustri Vero Wahyudi
I want to get the lowest value from My datagridview column!
我想从我的 datagridview 列中获取最低值!
The name of my datagridview is datagridview1
我的 datagridview 的名称是datagridview1
Here my datagridview :
这是我的数据网格视图:
|-Number-|
|---90---|
|---70---|
|---20---|
|---80---|
|---50---|
|---60---|
|-号码-|
|---90---|
|---70---|
|---20---|
|---80---|
|---50---|
|---60---|
I have been try some code :
我一直在尝试一些代码:
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
There is no Error. But the result is 60Not 20
没有错误。但结果是60不是20
What Happen?? Help Me Please!
发生什么事??请帮帮我!
采纳答案by Jadeja RJ
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)
For Minimum You have to Use That Maximum value
对于最小值,您必须使用该最大值
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)
回答by Indranil.Bharambe
try below code
试试下面的代码
Private Structure cell
Dim rowIndex As Integer
Dim columnIndex As Integer
End Structure
Dim cells = From r As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
Where Not r.IsNewRow _
Select CInt(r.Cells(0).Value)
Dim min As Integer = cells.Min
Dim minval As New cell With {.columnIndex = 0, .rowIndex = Array.IndexOf(cells.ToArray, min)}
for maximum---
最大——
Dim max As Integer = cells.Max
Dim maxAddress As New cell With {.columnIndex = 0, .rowIndex = Array.IndexOf(cells.ToArray, max)}

