Rearrange Data Gridview colum after load .

  • 'DataGridview binding event is that which rearange colum after binding but not effect into orignal datatable

    Private Sub DataGridView1_DataBindingComplete(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles DataGridView1.DataBindingComplete

    DataGridView1.Columns(0).DisplayIndex = 2
    DataGridView1.Columns(1).DisplayIndex = 1
    DataGridView1.Columns(2).DisplayIndex = 3
    DataGridView1.Columns(3).DisplayIndex = 4
    DataGridView1.Columns(4).DisplayIndex = 0

    '''''' Set Display Index as per colum show requirment'''''

    End Sub

    'first load into datagridiew 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

      Dim con As New SqlConnection("connection string")
    Dim cmd As New SqlCommand("Select UserName,UserID,DepartmentID,FullName,Password from Employee", con)
    Dim adap As New SqlDataAdapter(cmd)
    Dim dt As New DataTable
    DataGridView1.DataSource = dt

    End Sub

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week