Results 1 to 4 of 4

Thread: DataGridView - GetRowDisplayRectangle only works when form is visible

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    DataGridView - GetRowDisplayRectangle only works when form is visible

    Hi,

    I am running a website for a F1 racing game, where users can submit their laptimes and compete with each other for the fastest time.

    I am now trying to have my website create an image of the top-5 users every... 5 minutes or something, and copy it to the webserver somewhere I can link to. This way the image under that link will update with the latest information every 5 minutes.


    To layout the times (these also include the position (1 to 5), the username, the platform, the time of course, and some more details) I am using a DataGridView. I could take the long route and layout the specific 'columns' manually, but I thought using a grid was far easier.
    I simply set some properties of the grid to make it look nothing like a grid (basically hide the column and row headers and grid lines and give everything the same backcolor). Then I load the times into the grid, and take an image of it using the Control.DrawToBitmap method.

    This works fine, but it returns the entire grid. This is a problem because I made the grid extremely large (5000x5000) so that it can always accommodate the times regardless of the length of the usernames. So, the image I get is 5000 pixels wide while it only contains data in the first 500 px orso.

    I am currently using the GetRowDisplayRectangle and GetColumnDisplayRectangle methods to figure out the part of the grid that actually displays the times, and use that to cut the image down to the portion I need.

    But here's a problem: these methods only return something when the grid is on a form that is currently being shown! I am already giving the grid a parent form (even though I am just creating it in memory and it doesn't need to be displayed anywhere) because otherwise the data wouldn't load, but I was never showing that form.
    Now it turns out I do need to show the form, very briefly, in order to figure out the area that I need to take a snapshot from.

    Remember that this is all happening on a webserver, so I'm not absolutely sure if this is a problem. Is it ok for a webserver to have a form popping up and down every 5 minutes? Or will this cause problems? I honestly don't know but I don't think it's a good thing. Moreover, it also pops up on my own machine when I'm testing, and it's damn annoying.


    So my question is basically twofold:
    1. Maybe I should ask this in the ASP.NET forum, but is it a problem to show a form briefly every 5 minutes?
    2. Is there any other way to get these Get...DisplayRectangle methods to work without having the grid on a physically visible form?

    Thanks!

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: DataGridView - GetRowDisplayRectangle only works when form is visible

    Hey.
    Sorry are you using asp.net?Because you say datagridview.Do you mean datagrid?
    I'm new to asp but what i'm thinking but not sure if is doable( i think asp.net forum is the place to ask) is:
    You can add javascript properties to the gridview rows with e.Row.Attributes .
    Now what i use this for is to change the row bakcground or have it possible to maintain data when it's hidden.
    I was thinking if you can load the rows with js and make it so that you can get the drawing regardless if the grid is showing or not.It is just a though and i believe you can use that if and only if someone has the js code ready because i think it will be more pain than it's worth to try making it yourself.
    That was for question 2.
    On question 1, i don't think you will have a problem, apart from being annoying.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataGridView - GetRowDisplayRectangle only works when form is visible

    You should definitely not be using a Windows Form in a web app. You should use GDI+ to create an Image.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: DataGridView - GetRowDisplayRectangle only works when form is visible

    I am using ASP.NET for the website, but I am using a regular System.Windows.Forms.DataGridView to take a 'screenshot' from. As far as I know this isn't possible with a web grid, right?

    I am now using a windows form indeed, but I don't want to, I just don't know any other way. If I am not showing the form but merely creating the DataGridView in memory, is that such a big problem to use a winforms control?

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