As the title say,
DataGridview.ScrollBars = Vertical;
Assume the vision of DataGridview can contain 4 rows, if the row comes to 6, it has a Vertical ScrollBar. But if click the ScrollBar, the program will crash. If we set the DataGridview.ScrollBars = None, no problem will happen.
public partial class visitorLeave : Form
{
public visitorLeave()
{
InitializeComponent();
}
bool isWorkerStopped = false;
bool clickstart = false;
ManageEmployee me = null;
Thread tr1;
private void visitorLeave_Load(object sender, EventArgs e)
{
me = new ManageEmployee(10);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = me.DataSource;
tr1 = new Thread(new ThreadStart(Add));
tr1.IsBackground = true;
tr1.Start();
}
void Add()
{
while (!isWorkerStopped)
{
if (clickstart)
{
me.AddEmployee(new EmployeeData("new" + DateTime.Now.Ticks.ToString(), "0", "0", "0", "0", "0", null));
dataGridView1.DataSource = me.DataSource;
dataGridView1.UpdateRowHeightInfo(0, true);
clickstart = false;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
clickstart = !clickstart;
}
}