Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys i want to get all the data from a column in datagrid view and display it to message box using vb .get

What I have tried:

cs.ConnecttoDB1("execute _spselect_maxpednote '" & REID__Id & "'", "x")

If cs.assds6.Tables("x").Rows.Count = 0 Then

Else
If TextBox6.Text <> "Turnover-do" And TextBox6.Text <> "excess-fe" And TextBox6.Text <> "offset-fo" And TextBox6.Text <> "Turnover-csd" Then

Dim ms As String
ms = cs.assds6.Tables("x").Rows(0).Item("note") & vbNewLine & cs.assds6.Tables("x").Rows(1).Item("note") & vbNewLine & cs.assds6.Tables("x").Rows(2).Item("note")
MsgBox("" & ms, MsgBoxStyle.OkOnly, "PED Remarks")

End If
Posted
Updated 28-May-18 15:04pm

1 solution

Try creating a for next loop from 0 to the column count -1 and concatenate the text for the messagebox

see For...Next Statement (Visual Basic) | Microsoft Docs[^]

Im not sure how much other code you have as to whether your problem is getting the data from the table to the grid or just summating the column data to a string.

To summate the data use something like

Dim ms as string = ""
for x As Integer = 0 To DataGridView1.Column.Count -1
ms += DataGridView1.SelectedRows().Column(x).ToString() & vbLine
Next
Msgbox(ms)

If the issue is getting the data to the grid there are plenty of examples on the web on how to do that.

PS. Its a long time since I used VB so you will need to check my syntax
 
Share this answer
 
v3
Comments
flo1233 28-May-18 21:25pm    
im new in vb.net can you please teach me how please
RossMW 28-May-18 22:25pm    
See updated Answer....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900