|
-
Jan 29th, 2010, 01:20 PM
#1
Thread Starter
Addicted Member
[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.
-
Jan 29th, 2010, 01:32 PM
#2
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.
-
Jan 29th, 2010, 01:55 PM
#3
Thread Starter
Addicted Member
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?
-
Jan 29th, 2010, 02:47 PM
#4
-
Jan 29th, 2010, 02:51 PM
#5
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
 
-
Jan 29th, 2010, 03:06 PM
#6
Re: Very strange problem
Investigate your InitializeComponent sub. You didn't extend your DataGridView, is it a default class?
-
Jan 29th, 2010, 07:05 PM
#7
Thread Starter
Addicted Member
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
-
Jan 29th, 2010, 07:28 PM
#8
Thread Starter
Addicted Member
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!
-
Jan 29th, 2010, 08:20 PM
#9
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|