Results 1 to 9 of 9

Thread: [RESOLVED] Very strange problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Resolved [RESOLVED] Very strange problem

    Is there any particular reason that anyone can think of why when a datagrid view loads via the forms onload event, all the color assignments to cells and text are ignored? But if the datagrid view is reloaded via a button's onclick event there's no problem.

    This has just cropped up while I was working on a seemingly unrelated bit of code.

    I've stepped into the code on all the lines where I've changed the color of cells and text and it runs through it every time. I've even copied and pasted the entire page from a working backup and the problem's still there.

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Very strange problem

    When dealing with strange problems the first thing you should do is to post your code here. I'm sorry I've broken by crystal ball and my telepathic skills are worse than usual today.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Very strange problem

    I'm don't really want to post my code to you horrible lot

    No, but seriously I wouldn't know what part of it to post. Even if it wasn't top secret

    No constructor is called on the form and no attributes or methods are accessed from outside. The only object that is declared is that of the serializer class which does nothing more than "manipulate" objects of it's own type.

    The odd thing is that I've done a fair bit of formatting at runtime other than changing the color of parts of the dgv (background and foreground) and these display OK. For example: removing columns, naming columns, changing the text displayed on cells, changing the size of the datagridview, changing the widths of columns. Some of these are even "declared" inside the same loop structure as the for-mentioned.

    The only change I've made that I can think of that might have some bearing on the way the form is displayed is in the way the main container form closes down forms. But then I don't see how this would only affect the color when the form loads.

    Is there some kind of namespace I can declare at the top of the form perhaps?

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Very strange problem

    Imports PostYourCode
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Very strange problem

    Where does the color assignment happen? Is that also in the load event? is it before or after the datasource of the DGV is set? Have you stepped through the code to confirm that it is actually changing the assignment?
    My usual boring signature: Nothing

  6. #6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Very strange problem

    The color assignments come after the datasource on separate methods from the onload event.

    I have a system that enables the user to navigate through a record set by clicking on a "previous" and "next" button which works well. If I navigate away by clicking on the buttons the page loads with colors, even when I navigate back to the first page- just not when the form loads.

    I'm not sure how to check if the colors get assigned when the code "parses" through. If I hover over the counter variable (i) in a for loop in an assignment, the value does show correctly however:

    i.e.
    Code:
    dgv.Item(0, i).Style.BackColor = Color.Linen
    All I have on my sub declarations is this:

    Code:
      'empty constructor
        Public Sub New()
            InitializeComponent()
            pageNum = Nothing
        End Sub
    
        'full constructor
        Public Sub New(ByVal vpageNum As Integer)
            InitializeComponent()
            pageNum = vpageNum
            If Not pageNum = Nothing Then
                formatCells = False
            End If
        End Sub

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Very strange problem

    I forgot to mention that nothing is passed to the constructor when I call the form to view it. The parameter in the constructor (pageNum) is used when i export my database as an excel workbook.

    Thanks!

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Very strange problem

    OK got it. I was adding doing this:

    Code:
        Public Sub addView(ByVal vForm As Form)
            vForm.TopLevel = False
            Me.Controls.Add(vForm)
            vForm.Show()
    
        End Sub
    instead of this.

    Code:
        Public Sub addView(ByVal vForm As Form)
            vForm.TopLevel = False
            vForm.Show()
            Me.Controls.Add(vForm)
        End Sub
    Somehow I mixed up the 2 lines when i made a change to the function the which caused the presentation if the datagridview to play up.

    Thanks for your help anyway guys

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