using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication8
{
public partial class Form1 : Form
{
private BindingSource mybindingsource = new BindingSource();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connstring = "database=DataReadertest;server=server;uid=sa;pwd=msnrl;";
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
string sqlstr="select * from DrTest";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlstr,conn);
da.Fill(ds);
mybindingsource.DataSource = ds.Tables[0];
dataGridView1.DataSource = ds.Tables[0];
this.bindingNavigator1.BindingSource = mybindingsource;
}
private void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e)
{
dataGridView1.ClearSelection();
dataGridView1.Rows[0].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = 0;
}
private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e)
{
int rowindx = (dataGridView1.SelectedRows[0].Index - 1 + dataGridView1.RowCount) % dataGridView1.RowCount;
dataGridView1.ClearSelection();
dataGridView1.Rows[rowindx].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.SelectedRows[0].Index;
}
private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e)
{
int rowIndex = (dataGridView1.SelectedRows[0].Index + 1) % dataGridView1.RowCount;
dataGridView1.ClearSelection();
dataGridView1.Rows[rowIndex].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex;
}
private void bindingNavigatorMoveLastItem_Click(object sender, EventArgs e)
{
dataGridView1.ClearSelection();
dataGridView1.Rows[dataGridView1.RowCount - 2].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;
}
}
}