0

Dim MaxVal As Integer

For a = 0 To DataGridView1.RowCount - 1
If MaxVal < DataGridView1.Item(DataGridView1.ColumnCount - 1, a).Value Then
MaxVal = CInt(DataGridView1.Item(DataGridView1.ColumnCount - 1, a).Value)
End If
Next
MsgBox("The Optimum Value is " & MaxVal, 1, "Optimum Choice")
5
Contributors
14
Replies
15
Views
5 Years
Discussion Span
Last Post by mie.ilani
0

Just displaying code is not enough for us to understand ur problem....do explain ur problem in detail...

0

opssss. sorry! actually the code will dispaly the maximum number on datagridview. now, i want to display which row it is at message box. House 1 & 2 refer to the row name.

" The optimum value is 13 at House 1 and House 2"

0

" The optimum value is 13 at House 1 and House 2"

In this is 13 ur row number??

As I understood u want to display the row number of the item which will be clicked

Dim MaxVal As Integer
For a = 0 To DataGridView1.RowCount - 1
    MaxVal = DataGridView1.CurrentCell.RowIndex + 1
Next
MsgBox("The Optimum Value is " & MaxVal, 1, "Optimum Choice")

Please correct me if u need something else....

Edited by poojavb

0

nope. actually i have 10 rows, label as House 1 until House 10. the comand do to check the highest number (MaxVal).

now, i want msgbox prompt the output as " The optimum number is 13 at House 1, House 2"

optimum number refers to the highest number. u can refer to the attachment. tq =D

0

as i understand is that you have 10 rows and you have a column name house and a optimum value
now you just want to get the largest optimum value of any house ? if i m right then you can do like this.

here is code if there is single column of optimum value in your grid.

    dim maxVal as integer
     maxVal = 0 ;
     for i = 0 to datagridview1.rows.count -1 
        if maxVal < datagridview1.item(2,i).value.tostring then
        maxVal = datagridview1.item(2,i).value.tostring
        end if
     next
    msgbox ("your string here" & maxVal & " your string here.")

here is code if there is more then one column in the grid of optimum value ,

  dim maxVal as integer
     maxVal = 0 ;
     for i = 0 to datagridview1.rows.count -1 
         for a = 0 to datagridview1.column.count -1 
           if maxVal < datagridview1.item(a,i).value.tostring then
              maxVal = datagridview1.item(a,i).value.tostring
           end if    
         next
    next
    msgbox ("your string here" & maxVal & " your string here.")

as i typed all this code here so may be there is some mistake in it , so please if you find any do tell me here so that i can solve it , one more thing , please always post question with full description, so that you can get good an fast help and also post attachment if possible.

Best Regards

Muhammad Waqas Aslam

0

you're right Waqas. other than show the maxValue, i want to show the Row name that refer to the maxValue.

but the code given have one error which is

Error 1 'column' is not a member of 'System.Windows.Forms.DataGridView'.

0

here are the attachement. u can see the maxvalue in last column.

0

Create a second var to hold the house number. Then when you set the maxVal you'll set the house as well.

0

yup. but since i dont know how to do the Rows code, i'll need sumone to help. =D

0
Dim house string 
For a = 0 To DataGridView1.RowCount - 1
If MaxVal < DataGridView1.Item(DataGridView1.ColumnCount - 1, a).Value Then
MaxVal = CInt(DataGridView1.Item(DataGridView1.ColumnCount - 1, a).Value)
house = DataGridView1.Item(1,a) 'Change 1 to reflect the correct column 
elseif MaxVal = DataGridView1.Item(DataGridView1.ColumnCount - 1, a).Value Then 
house &= ", " & DataGridView1.Item(1,a) 'Change 1 to reflect the correct column 
End If
Next
MsgBox("The Optimum Value is " & MaxVal & " in houses: " & house , 1, "Optimum Choice")

Edited by adam_k

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.