I want to make Paging in DataGridView I seen some tutorials but all of used data table and data set to fill the 'Datagridview' but in my code, I don't want to show all items and also I have an image button and another stuff.
what I want is to add paging to my grid so the user can choose what to show and load the Datagrid view smoothly. what I want is something like this:
https://www.sourcecodester.com/sites/default/files/images/admin/datagridview_paging.jpg
thank you.
This is the code that I Use to fill Gridview from the database:
What I have tried:
Sub FillGrid()
DataGrid1.CancelEdit()
DataGrid1.Columns.Clear()
DataGrid1.DataSource = Nothing
Dim btnDelete As New DataGridViewButtonColumn()
btnDelete.FlatStyle = FlatStyle.Flat
Dim btnImage As New DataGridViewButtonColumn()
btnImage.FlatStyle = FlatStyle.Flat
Dim column = New CalendarColumn() With {.HeaderText = "Date"}
column.DefaultCellStyle.Format = "dd/MM/yyyy"
column.DataPropertyName = "Date"
DataGrid1.Columns.Insert(0, btnDelete)
DataGrid1.Columns.Add("", "Id")
DataGrid1.Columns.Add("", "Name")
DataGrid1.Columns.Add("", "nickname")
DataGrid1.Columns.Add("", "city")
DataGrid1.Columns.Add("", "phone 1")
DataGrid1.Columns.Add("", "phone 2")
DataGrid1.Columns.Add("", "phone 3")
DataGrid1.Columns.Add("", "Email")
DataGrid1.Columns.Add(btnImage)
DataGrid1.Columns.Add(column)
DataGrid1.Columns.Add("", "image")
DataGrid1.Columns.Add("", "")
DataGrid1.Columns(11).Visible = False
Const sqlstring As String = "Select * FROM customers"
If SQL.conn.State = ConnectionState.Open Then
SQL.conn.Close()
End If
SQL.conn.Open()
Dim adt As New SqlDataAdapter(sqlstring, SQL.conn)
Dim dt As New DataTable
adt.Fill(dt)
Dim i As Integer
For i = 0 To dt.Rows.Count - 1
DataGrid1.Rows.Add()
DataGrid1.Rows(i).Cells(1).Value = dt.Rows(i).ItemArray(0)
DataGrid1.Rows(i).Cells(2).Value = dt.Rows(i).ItemArray(1)
DataGrid1.Rows(i).Cells(3).Value = dt.Rows(i).ItemArray(2)
DataGrid1.Rows(i).Cells(4).Value = dt.Rows(i).ItemArray(3)
DataGrid1.Rows(i).Cells(5).Value = dt.Rows(i).ItemArray(4)
DataGrid1.Rows(i).Cells(6).Value = dt.Rows(i).ItemArray(5)
DataGrid1.Rows(i).Cells(7).Value = dt.Rows(i).ItemArray(6)
DataGrid1.Rows(i).Cells(8).Value = dt.Rows(i).ItemArray(7)
DataGrid1.Rows(i).Cells(10).Value = dt.Rows(i).ItemArray(9)
DataGrid1.Rows(i).Cells(11).Value = dt.Rows(i).ItemArray(10)
Next
SQL.conn.Close()
For i = 0 To DataGrid1.RowCount - 1
DataGrid1.Rows(i).HeaderCell.Value = CStr(i + 1)
Next
End Sub