hello
i use this method for go next row in datagridview
private void btnNext_Click(object sender, EventArgs e)
{
if (grdQustion.Rows.Count >= 1)
{
int i = grdQustion.CurrentRow.Index + 1;
if (i >= -1 && i < grdQustion.Rows.Count)
grdQustion.Rows[i].Selected = true;
}
}
But I've written some code in grdQustion_RowEnter .When I go to the next row of code above the code will not run into grdQustion_RowEnter
Even CurrentRow. Index does not change
how can i go next row in datagridview with button??
Loading
VulpesPosted Nov 18, 2011, 1:44 PM
Satyapriya NayakPosted Nov 19, 2011, 12:15 AM
You can do it by using dataGrid as...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
DataTable dt;
String str;
public Form1()
{
InitializeComponent();
}
private void btn_next_Click(object sender, EventArgs e)
{
dataGrid1.UnSelect(dataGrid1.CurrentRowIndex);
dataGrid1.CurrentRowIndex += 1;
dataGrid1.Select(dataGrid1.CurrentRowIndex);
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "student");
con.Close();
dt = ds.Tables["student"];
dataGrid1.ReadOnly = true;
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "student";
}
}
}
Thanks
MohammadaliPosted Nov 18, 2011, 1:13 PM
The second time I click on the button. Does not go to the next row
The index 0 stays
The event also will not run commands rowenter
Records are added to the Data Grid
The data source is not used
Raminsha RafeekPosted Nov 18, 2011, 12:40 PM
//This code selects the next row in the datagrid view while also making sure that it is not
//The last row.
if(grdQustion.CurrentRow.Index < grdQustion.Rows.Count)
{
grdQustion.Rows[grdQustion.CurrentRow.Index + 1].Selected = true;
}