How to get dragged column in datagridview when All

2019-09-09 05:25发布

问题:

I have a windows form application in which i have a datagridview with AllowUserToOrderColumns = true, then user change column order via drag and drop.

How can i know which column is dragged ?

回答1:

When you set AllowUserToOrderColumns = true then you will know the column name in ColumnDisplayIndexChanged

Private Sub Datagridview1_ColumnDisplayIndexChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles dgvGuru.ColumnDisplayIndexChanged

     MsgBox(e.Column.Name)

End Sub