滚动条无法使用C#在DataGridView中工作

发布于 2025-01-23 00:10:22 字数 1883 浏览 2 评论 0原文

我构建了一个应用程序,该应用程序通过将来自不同存储过程(SQL Server)的数据从数据表中拉到数据级来填充数据杂志。

当填充数据杂志时,我可以使用鼠标向下滚动,但是将垂直和水平滚动条以及“向上/向下/左/右”按钮弄清楚,单击它们没有效果。

我尝试了多种解决方案,例如 this and this 没有任何运气。

在他们正确显示的代码的初始阶段,在我决定使用线程填充数据杂志之后,这开始发生(我想在存储过程执行时显示一个不错的“加载” GIF,主要是因为某些存储过程采取了几个过程,执行分钟,具体取决于所需的数量)。

这是我的代码的片段:

    public void btnSearch_Click(object sender, EventArgs e)
    {
        btnSave.Enabled = false;
        pbLSearching.Visible = true;       // I used Threads just so I can display this one
        lblExecutingQuery.Visible = true;  // along with this.

        startDate = dtpStartDate.Text;     // These are my parameters needed for the  
        endDate = dtpEndDate.Text;         // stored procedures

        dataGridView1.DataSource = null;   // These two are here to clear it out when I 
        dataGridView1.Refresh();           // run a different search

        if (tabSearchOptions.SelectedTab == tabSearchOptions.TabPages["tabSearchByStation"])
        {            
        Thread dataThread = new Thread(getData);
        dataThread.Start();              
        }
    }   
   
    public void getData()
    {
        
        if (FTS1 == true)
        {
            dataGridView1.DataSource = FTS_1.GetFunctionalData(startDate, endDate);
           
        }
        else if (FTS2 == true)
        {
            dataGridView1.DataSource = FTS_2.GetFunctionalData(startDate, endDate);
        }
         .
         .
         .
         // and so on for the rest of the stations and some unrelated code

任何帮助将不胜感激。谢谢。

I built an app that fills a datagridview by pulling data from different stored procedures(SQL Server) into a DataTable.

When the datagridview is filled, I can scroll down using my mouse, but the vertical and horizontal scrollbars along with the "up/down/left/right" buttons are greyed out, clicking on them has no effect.

I've tried multiple solutions, like this and this without any luck.

At the initial stages of the code they were showing correctly, this began to happen after I decided to fill the datagridview using Threads (I wanted to have a nice "loading" GIF displayed while the stored procedure executes, mostly because some stored procedures take several minutes to execute, depending on the amount of that that is required).

Here's a fragment of my code:

    public void btnSearch_Click(object sender, EventArgs e)
    {
        btnSave.Enabled = false;
        pbLSearching.Visible = true;       // I used Threads just so I can display this one
        lblExecutingQuery.Visible = true;  // along with this.

        startDate = dtpStartDate.Text;     // These are my parameters needed for the  
        endDate = dtpEndDate.Text;         // stored procedures

        dataGridView1.DataSource = null;   // These two are here to clear it out when I 
        dataGridView1.Refresh();           // run a different search

        if (tabSearchOptions.SelectedTab == tabSearchOptions.TabPages["tabSearchByStation"])
        {            
        Thread dataThread = new Thread(getData);
        dataThread.Start();              
        }
    }   
   
    public void getData()
    {
        
        if (FTS1 == true)
        {
            dataGridView1.DataSource = FTS_1.GetFunctionalData(startDate, endDate);
           
        }
        else if (FTS2 == true)
        {
            dataGridView1.DataSource = FTS_2.GetFunctionalData(startDate, endDate);
        }
         .
         .
         .
         // and so on for the rest of the stations and some unrelated code

Any help will be appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好菇凉咱不稀罕他 2025-01-30 00:10:22

好吧,事实证明,该解决方案实际上是在这里回答,我必须将滚动条属性设置为“无”,然后在我的线程中使用调用会设置它们

Alright, turns out that the solution was actually here, as someone replied to the answer, I had to set the scrollbars properties to "none" then using Invoke inside my thread would set them up

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文