Hi!
I nee to scroll down data automatically on my datagrid and displaying on my textboxes.
I have on my form two textboxes (txtBox1 and txtBox2), Datagridview and 2 Buttons (btnUp and btnDown).
What I need? Clicking on a button I would like to see data scrolling automatically from the bottom until at the end of my datagridview.
But I wrote these code to scroll up/down manually datas with my Buttons (btnUp and btnDown). Let's go carefully.
Code for btnUp:
private void btnUp_Click(object sender, EventArgs e)
{
if (dataGridView1.CurrentRow == null) return;
if (dataGridView1.CurrentRow.Index - 1 >= 0)
{
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.CurrentRow.Index - 1].Cells[0];
dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Selected = true;
Code for btnDown:
private void btnDown_Click(object sender, EventArgs e)
{
if (dataGridView1.CurrentRow == null) return;
if (dataGridView1.CurrentRow.Index + 1 <= dataGridView1.Rows.Count - 1)
{
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.CurrentRow.Index + 1].Cells[0];
dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Selected = true;
}
Code that display on textboxes:
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
textBox1.Text = row.Cells["0"].Value.ToString();
textBox2.Text = row.Cells["1"].Value.ToString();
button4.PerformClick();
}
}
Then I need when I click on a bntDown I need to see scrolling automatically datas on my Datagridview until at the last record. But displaying each row's datas on my textboxes (txtBox1and txtBox2)
Thank you very much.
Madhanmohan DevarajanPosted Apr 28, 2017, 10:05 AM