Guys I am trying to implement paging in my datagridview through bindingnavigator in C# windows forms application.
I have simply dragged datagridview and bindingnavigator from Toolbar to form. Datagridview is databounded to a database table in SQL server using dataset. I have added 3 extra buttons to gridview that will be doing some function.
Now I have never used bindingnavigator before, so I just selected bindingsource of datagridview1 for datasource of bindingnavigator from its properties.
This is how my form looks upon running :
Currently, datagridview1 displays all the records in my table (31, as of now) and binding navigator next button just takes me to next record (for example, from TicketID=1 to TicketID=2).
Now, what I want to do is :
1.) Datagridview should only display 10(or 50) records per page, and bindingnavigator control should be used to switch between pages so that the UI remains responsive and it becomes more "memory-efficient" because eventually my database will have thousands of records.
2.) BindingNavigator's controls should appear in center of the form, not to the left/right. I couldn't set it to center from properties.
Code behind my form :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form9 : Form
{
public Form9()
{
InitializeComponent();
}
private void Form9_Load(object sender, EventArgs e)
{
this.CenterToScreen();
try
{
this.tblTicketDetailTableAdapter.Fill(this.sTDataSet4.tblTicketDetail);
}
catch
{
MessageBox.Show("Error : Cannot establish a valid connection to database.", "SQL SERVER ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView1.Columns["Detail"].Index)
{
//some code
}
else if (e.ColumnIndex == dataGridView1.Columns["Close"].Index)
{
//some code
}
else if (e.ColumnIndex == dataGridView1.Columns["ViewDetail"].Index)
{
//some code
}
}
}
Now what can I do to make bindingnavigator
work as paging control?