C# DataGridView在填充异步后隐藏滚动条

C# DataGridView在填充异步后隐藏滚动条,c#,asynchronous,datagridview,task,C#,Asynchronous,Datagridview,Task,在我的表单中,我使用tab控件将4个数据网格分隔开 当我尝试用异步任务填充它时,滚动条消失了 这是我的密码 await Task.Run(() => { PopulateHistoryAll(items); PopulateHistoryParkerIn(parkerIn); PopulateHistoryParkerOut(parkerOut); Populat

在我的表单中,我使用tab控件将4个数据网格分隔开

当我尝试用异步任务填充它时,滚动条消失了

这是我的密码

        await Task.Run(() =>
        {
            PopulateHistoryAll(items);
            PopulateHistoryParkerIn(parkerIn);
            PopulateHistoryParkerOut(parkerOut);
            PopulateHistoryMonthlyIn(monthlyIn);
            PopulateHistoryMonthlyOut(monthlyOut);
        });
我试着使用这个代码

        this.Invoke((MethodInvoker)delegate
        {
            //DataGridview Refreshment
            dgParkerIn.Enabled = true;
            dgParkerIn.ScrollBars = ScrollBars.Both;
        });
但它不起作用


请帮助我,谢谢:)

这是我的填充表代码。他们都一样

    private void PopulateHistoryAll(IEnumerable<HistoryModel> items)
    {
        dgHistoryAll.Rows.Clear();
        if (items.Count() > 0)
            dgHistoryAll.Rows.Add(items.Count());

        var row = 0;
        foreach (var item in items)
        {
            dgHistoryAll[dtlAllRow.Index, row].Value = row + 1;
            dgHistoryAll[dtlAllTransitId.Index, row].Value = item.Id;
            dgHistoryAll[dtlAllTerminal.Index, row].Value = item.Terminal;
            dgHistoryAll[dtlAllORNo.Index, row].Value = item.ORNumber;
            dgHistoryAll[dtlAllPlateNo.Index, row].Value = item.PlateNo;
            dgHistoryAll[dtlAllTicketNo.Index, row].Value = item.TicketNumber;
            dgHistoryAll[dtlAllDateTimeIn.Index, row].Value = item.TimeIn;
            dgHistoryAll[dtlAllDateTimeOut.Index, row].Value = item.TimeOut;
            dgHistoryAll[dtlAllDurationOfStay.Index, row].Value = item.Duration;
            dgHistoryAll[dtlAllRatesName.Index, row].Value = item.RateName;
            dgHistoryAll[dtlAllCoupon.Index, row].Value = item.Coupon;
            dgHistoryAll[dtlAllMonthlyRFID.Index, row].Value = item.MonthlyRFID;
            dgHistoryAll[dtlAllMonthlyName.Index, row].Value = item.MonthlyName;
            row++;
        }
        this.Invoke((MethodInvoker)delegate
        {
            dgHistoryAll.ScrollBars = ScrollBars.Both; 
        });
    }
private void PopulateHistoryAll(IEnumerable items)
{
dgHistoryAll.Rows.Clear();
如果(items.Count()>0)
dgHistoryAll.Rows.Add(items.Count());
var行=0;
foreach(项目中的var项目)
{
dgHistoryAll[dtlAllRow.Index,row].Value=row+1;
dgHistoryAll[dtlAllTransitId.Index,行].Value=item.Id;
dgHistoryAll[dtlAllTerminal.Index,行].Value=item.Terminal;
dgHistoryAll[dtlAllORNo.Index,第行].Value=item.ORNumber;
dgHistoryAll[dtlAllPlateNo.Index,第行].Value=item.PlateNo;
dgHistoryAll[dtlAllTicketNo.Index,第行].Value=item.TicketNumber;
dgHistoryAll[dtlAllDateTimeIn.Index,第行].Value=item.TimeIn;
dgHistoryAll[dtlAllDateTimeOut.Index,第行].Value=item.TimeOut;
dgHistoryAll[dtlAllDurationOfStay.Index,行].Value=item.Duration;
dgHistoryAll[dtlAllRatesName.Index,行].Value=item.RateName;
dgHistoryAll[DtlAll优惠券.Index,第行].Value=item.优惠券;
dgHistoryAll[dtlallMonthlyFID.Index,第行].Value=item.monthlyFID;
dgHistoryAll[dtlAllMonthlyName.Index,行].Value=item.MonthlyName;
行++;
}
此.Invoke((MethodInvoker)委托
{
dgHistoryAll.ScrollBars=滚动条。两者都有;
});
}

我终于找到了解决办法

虽然这很奇怪

我试图删除datagrid,添加并创建另一个,然后


它可以工作,idk为什么。

需要查看Populate*方法的代码。我通常会让那些Populate*方法填充5个数据表,然后在适当的时候将它们分配给每个相关的datagridview.DataSource(如果将其作为异步工作的一部分,则通过调用),并且不使用scrollbars属性。当使用这种简单的填充方式时,datagridview从来没有失败过按需显示其滚动条