This might be of interest to you:
Image Thumbnail Preview in DataGridView[
^]
If you use a
BindingList
(recommended) then you can do it like this:
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestForm1
{
public partial class Form1 : Form
{
private BindingList<MyClass> masterBindingList;
public Form1()
{
InitializeComponent();
this.Init();
}
private void Init()
{
this.masterBindingList = new BindingList<MyClass>();
this.dataGridViewMaster.DataSource = this.masterBindingList;
}
private void ButtonAddRowClick(object sender, EventArgs e)
{
var rowIndex = this.dataGridViewMaster.RowCount;
this.AddRow(rowIndex);
this.ScrollToRow(rowIndex);
}
private void AddRow(int rowIndex)
{
this.masterBindingList.Add(new MyClass { Title = "Row " + rowIndex.ToString() });
}
private void ScrollToRow(int rowIndex)
{
this.dataGridViewMaster.ClearSelection();
this.dataGridViewMaster.FirstDisplayedScrollingRowIndex = rowIndex;
this.dataGridViewMaster.Focus();
}
public class MyClass
{
public string Title { get; set; }
}
}
}