I'm currently seeing the following problem: I have a DataGridView that is filled by a Task running in the background. After the task is finished, the scrollbars and cells aren't shown properly in the DataGridView somehow... After resizing the dialog to fullscreen mode (maximized), the scrollbars are shown properly... Whenever the resizing is done the other way (to minimized), the scrollbar fails again... Any ideas here? Is there any refresh event I can trigger from the Task to readjust the scrollbars and cells?
**Additional information: ** The DataGridView is packed onto a TableLayoutPanel with Dock = Fill.
Edit: The data loading is done via
private void TryLoadData()
{
try
{
LoadData();
}
catch (Exception ex)
{
//Just some error logging
_log.Error(ex);
_errorHandler.Show(ex);
}
}
private void LoadData()
{
ClearRows();
//Loading from database
var data = _databaseAdapter.Get<Data, bool>(x => !x.Deleted);
foreach (var singleDatum in data)
LoadDataRowToDataGridView (singleDatum);
}
private void ClearRows()
{
this.UiThreadInvoke(() => { DataGridView.Rows.Clear(); });
}
private void LoadDataRowToDataGridView(Data singleDatum)
{
this.UiThreadInvoke(() => { DataGridView.Rows.Add(singleDatum.Id, singleDatum.Name); });
}
Started via:
new Task(TryLoadData).Start();
UiThreadInvoke:
using System;
using System.Windows.Forms;
namespace UIExtensions
{
public static class UiThreadInvokeExtension
{
public static void UiThread(this Control control, Action code)
{
if (control.InvokeRequired)
{
control.BeginInvoke(code);
return;
}
code.Invoke();
}
public static void UiThreadInvoke(this Control control, Action code)
{
if (control.InvokeRequired)
{
control.Invoke(code);
return;
}
code.Invoke();
}
}
}
datagridview
inbackgroundworker
? – kocica