I have a problem, with a DataGridView which get data from another thread. I'm not the best in english, so here is the code:
private void TaskLoad()
{
List<taskafterdb> tasklist = new List<taskafterdb>();
this.tasklistTableAdapter.FillTaskBoard(sHADOWv5_testDataSet.tasklist)
var s = from x in sHADOWv5_testDataSet.tasklist
orderby x.DATE ascending
select x;
dgv_tasks.DataSource = s.AsDataView();
foreach (var task in sHADOWv5_testDataSet.tasklist)
{
tasklist.Add(new taskafterdb { DATE = task.DATE, COLOR = task.COLOR });
}
tasklist = tasklist.OrderBy(t => t.DATE).ToList();
dgv_tasks.DataSource = tasklist;
foreach (DataGridViewColumn column in dgv_tasks.Columns)
{
column.Frozen = false;
}
dgv_tasks.Columns["TASK"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dgv_tasks.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
dgv_tasks.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgv_tasks.ScrollBars = ScrollBars.Both;
dgv_tasks.Controls[0].Enabled = true;
dgv_tasks.Controls[1].Enabled = true;
}
This is the TaskLoad() method, which fills the DGV with rows.
If I put this method to the main thread eg.: Form1_Load, the scrollbars are working perfectly. The big problem is that I should refresh the data from another thread:
static public Thread dohardwork;
public void Form1_Load(object sender, EventArgs e)
{
dohardwork = new Thread(hardwork);
dohardwork.Start();
}
private void hardwork()
{
TaskLolad();
Form1_Resize(this, null);
IsHardworkDone = true;
fadeintimer.Enabled = true;
dohardwork.Abort();
}
And then, the scrollbars are gone... There is a little space for it, but nothing more. I can scroll with mouse, or with arrow keys, but nothing more...
Thank you for any kind of help! :)