Copy datagridview selected column

Steve36445

Well-known member
Joined
Dec 23, 2007
Messages
58
Programming Experience
10+
Hi, I'm still struggling with an unbound dgv invb 2008.

Could you please help me access cells in a slelected coumn of a dgv.

I want to place the selected column into an array so that I can manipulate it further.

Thanks,

Steve
 
This code is a workaround but works, I tried iterating through the cells in the selected column but I can't figure it out so here it is:

VB.NET:
Private Sub datMain_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles datMain.ColumnHeaderMouseClick

        Dim arr() As String = {}

        For Each r As DataGridViewRow In datMain.Rows
            For Each c As DataGridViewColumn In datMain.Columns
                If c.Index = e.ColumnIndex Then
                    ReDim Preserve arr(arr.GetUpperBound(0) + 1)
                    arr(arr.GetUpperBound(0)) = r.Cells(c.Index).Value
                End If
            Next
        Next

    End Sub
 
Back
Top