Set cursor on new created row

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
how to set cursor in datagridview on new created row.
Source:
private void btnAdd_Click(object sender, EventArgs e)
{
TtfMovieTypeEditor aEditor = new TtfMovieTypeEditor();
if(aEditor.ShowDialog() == DialogResult.OK)
{
DataRow dataRow;
dataRow = dtMovieTypes.NewRow();
dataRow["Name"] = aEditor.edtName.Text;
dtMovieTypes.Rows.Add(dataRow);
//now datagridviewTypes.Select() not works
//I need something like datagridviewTypes.Locate(dataRow)
//to synchronize grid and dataset
};
aEditor.Dispose();
}

Thanks in advance
Peter
 
Hi

Try using the BindingContext as:
dtMovieTypes.Rows.Add(dataRow);
then:
this.BindingContext[datagridviewTypes.dtMovieTypes].Position =
datagridviewTypes.Tables["dtMovieTypes"].Rows.Count - 1;
 
But if grid is sorted then its doesn't works



Vivek Thakur said:
Hi

Try using the BindingContext as:
dtMovieTypes.Rows.Add(dataRow);
then:
this.BindingContext[datagridviewTypes.dtMovieTypes].Position =
datagridviewTypes.Tables["dtMovieTypes"].Rows.Count - 1;
 
Back
Top