I want to navigate to a record in Datagridview by selecting/click on a record without using a button click.
and display a record number,or current record number.
Please help here is my code snippet.
C#
private void labelUpdate()
{
if (hwdg.SelectedRows.Count>=inc)
{
hwdg.FirstDisplayedScrollingRowIndex = inc;
hwdg.Rows[inc].Selected = true;
//inc++;
label27.Text = "Record" + (inc + 1) + " of " + ds2.Tables["tblComp"].Rows.Count;
}
else if(hwdg.SelectedRows.Count<=inc)
{
hwdg.Rows[inc - 1].Selected = true;
label27.Text = "Record" + (inc + 1) + " of " + ds2.Tables["tblComp"].Rows.Count;
}
}3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Madito Kevin5 pointsPosted May 6, 2015, 11:32 AM EDT
Madito Kevin5 pointsPosted May 10, 2015, 8:18 AM EDT
IsraelRank #1,223 · 1.1K pointsPosted Apr 7, 2015, 5:09 AM EDT
Listen, this example use a MS ACCESS database.
public partial class Facturacao : Form
private void dvgFrm_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = this.dvgFrm.Rows[e.RowIndex]; if (dvgFrm != null) textBox1.Text = row.Cells["name"].Value.ToString(); textBox2.Text = row.Cells["passportenumber"].Value.ToString(); } }