VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a column in datagridview called Name - Product. There are some data in the row such as- apple, orange, pineapple, grape, litchi
I would like to see these data through the button click event in the Multiline Text box-1 as below.
Apples,
Orange,
Pineapple,
Grapes,
Litchi
I don't understand how this can be done.
I seek the cooperation of experts.
And thanks in advance.
Hi
Here is one way to do it. A stand alone example.
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' add some test data
With DataGridView1
.Rows.Add(Nothing, "Apple")
.Rows.Add(Nothing, "Orange")
.Rows.Add(Nothing, "Pineapple")
.Rows.Add(Nothing, "Grapes")
.Rows.Add(Nothing, "Litchi")
End With
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Clear()
Dim comma As String = ","
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If Not i = DataGridView1.NewRowIndex Then
Dim s As String = DataGridView1("Column2", i).Value.ToString
If i < DataGridView1.NewRowIndex - 1 Then
TextBox1.Text &= s & ","c & vbCrLf
Else
TextBox1.Text &= s
End If
End If
Next
End Sub
End Class