Results 1 to 6 of 6

Thread: [RESOLVED] Loading a Gridview with data appears white on the load process

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Resolved [RESOLVED] Loading a Gridview with data appears white on the load process

    Hi.

    I'm loading a datagridvew with data. I have one text column and one image column
    I have created 2 columns manually on the designer and I'm passing a: DataGridView1.Rows.Add(email, img) on a loop.
    My problem is that since I'm passing lot of rows, until the process is complete, I get a white background in place of the gridview.
    I can see the scroll bar loading stuff but the gridview is white. I used suspend and begin layout with no avail.

    I have used threading to add the rows. Maybe it's spoiling something? Also the Gridview is on another form from the main form.
    I'm opening the gridview form, suspend the layout and begin adding rows with threading.

    To be on the safe side, here is the rows add code, in case there is something wrong:

    Code:
     Private Delegate Sub addrowInvoker(ByVal email As String, ByVal okno As Boolean)
    
        Public Sub addrow(ByVal email As String, okno As Boolean)
            If Me.DataGridView1.InvokeRequired Then
                Me.DataGridView1.Invoke(Sub()
                                            If okno = True Then
                                                Dim img As Image = ResizeImage(My.Resources.check_mark, 15, 15, False)
                                                DataGridView1.Rows.Add(email, img)
                                            Else
                                                Dim img As Image = ResizeImage(My.Resources.x, 15, 15, False)
                                                DataGridView1.Rows.Add(email, img)
                                            End If
                                        End Sub)
            Else
    
                If okno = True Then
                    Dim img As Image = ResizeImage(My.Resources.check_mark, 15, 15, False)
                    DataGridView1.Rows.Add(email, img)
                Else
                    Dim img As Image = ResizeImage(My.Resources.x, 15, 15, False)
                    DataGridView1.Rows.Add(email, img)
                End If
    
            End If
        End Sub
    The image issue:
    Name:  Clipboard01.jpg
Views: 303
Size:  13.1 KB
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Loading a Gridview with data appears white on the load process

    You really shouldn't be accessing the same property of My.Resources over and over again like that. Each time you do that, you are extracting data and creating an Image object. You should be getting each resource Image and calling ResizeImage on it once only and then assigning the result to a field. That will probably speed things up a bit.

    As for seeing the grid rows as they are added, you'd probably have to call Refresh on the grid but, if you do that, the whole process will take longer. I'd suggest that you should be creating a list of objects on that secondary thread and then passing it to the UI thread once only and binding it. You're making the whole thing slower by going back and forth the way you are currently.

  3. #3

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Loading a Gridview with data appears white on the load process

    OK.
    I did not know that My.Resources would slow things down. I though it was cached and did not matter if I was calling it like that.
    Will fix that. Yes imageresize is called again, will fix that also.

    Also I would create a list of objects. See if that would make any difference. But is this behavior expected in large result sets? I usually have a page separator so I do not see differences but this is not the case right now.

    Thanks.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Loading a Gridview with data appears white on the load process

    I wouldn't say that the behavior is either expected, or not. It's possible, and if it happens, you have to find some kind of workaround. I have an application where loading one grid took several seconds. Because of that, I loaded a datatable in a secondary thread when the project loaded. The user couldn't get to the form where it was displayed for many seconds, which gave the thread time to complete. Therefore, by the time the form was ready to show, it was just a matter of binding the datatable, which was fast. In other words, I found one part of one form was slowing down loading the form, so I moved that part to a totally different place in the program, which solved the problem. You may not be able to do the same thing, but you have the same problem, so you just need to find a solution that will work for you.

    If the thread can build the data long before the form is needed, that would be great. If the thread can't start until the form is needed, then you will have to do something like put up a facade for the user to see while the data loads behind it. Not as nice, certainly, but workable.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Loading a Gridview with data appears white on the load process

    I would not go that far as to super fix everything.
    Fixing the image as JMC suggested boosted up time a little but still white grid.
    Out of curiosity, I used refresh and what it does is, it whites up, waits a while and then it starts sloooooowwwly show the rows.
    I guess I can put the needed data on a list before starting the grid load, that is fast, and then I can pass the list to the databind of the gridview.
    Would that be something to try out?

    Thanks.
    Last edited by sapator; Mar 14th, 2018 at 09:54 AM.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Loading a Gridview with data appears white on the load process

    OK.
    I have turn this to a list of string,image.
    Gridview now loads as expected.

    Thanks!
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width