Results 1 to 26 of 26

Thread: DGV Column sometimes decides to not be visible.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    DGV Column sometimes decides to not be visible.

    I have this DGV that is supposed to display thusly:

    Name:  DGV2.jpg
Views: 276
Size:  5.8 KB

    However, occasionally it will display without showing the last column:

    Name:  DGV1.jpg
Views: 276
Size:  4.7 KB

    The application will run fine and show the first display time after time, but then, for no reason that I have been able to discern, the second display will occur. Whenever this happens the only way I have been able to restore the first display is to close the application and start it again. To me it is a gremlin somewhere screwing with my Karma, but maybe someone might know, off the top of their head, what I am doing wrong and why this occurs.

    I guess I could declare that the column .Visible = True might help, but I have no idea why this would be so.

    The code for the display is below:

    Code:
                'Setup DGV
                Me.Width = 1069
                ttlInfo.Width = 1029
                grpCR.Location = New Point(212, 51)
                pnlSign.Width = 1031
                Me.LnkChangeApproveTableAdapter.FillByChangeID(Me._MasterBase5_0DataSet.lnkChangeApprove, glbintChangeID)
                dgvSignList.DataSource = Me._MasterBase5_0DataSet
                dgvSignList.Height = 406
                dgvSignList.Width = 1035
                dgvSignList.DataMember = "lnkChangeApprove"
                dgvSignList.Columns(0).Visible = False
                dgvSignList.Columns(1).Visible = False
                dgvSignList.Columns(2).Visible = False
                dgvSignList.Columns(3).HeaderText = "Name"
                dgvSignList.Columns(3).Width = 225
                dgvSignList.Columns(4).HeaderText = "Job Title"
                dgvSignList.Columns(4).Width = 250
                dgvSignList.Columns(5).HeaderText = "Department"
                dgvSignList.Columns(5).Width = 225
                dgvSignList.Columns(6).HeaderText = "Signature"
                dgvSignList.Columns(6).Width = 325
                dgvSignList.Columns(7).Visible = False
                dgvSignList.Columns(8).Visible = False
                dgvSignList.Columns(9).Visible = False

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

    Re: DGV Column sometimes decides to not be visible.

    You say "time after time". What does that mean exactly? Are you clicking a Button in that form to reload the data? Opening that form repeatedly form somewhere else? Running the program repeatedly? I'd probably suggest adding some tracing code that outputs information about the app state as you run it. When the anomaly occurs, you can then examine that trace output and see how it differs on that occasion to previous working occasions.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    I would have thought that you would understand the term, "time after time". So let me clarify that for you. Time after Time would mean anything that is repetitively done. In this case I, time after time, executed an application (in this case a from) that has a DGV on it that displays the rows and column I included with the post.

    Now, I am assuming you are asking for the sequence of events that leads up to this which follows:

    1. I have a Change Request form that has a button. I click the button and the form containing the DGV is opened and the code I included is executed.

    I would probably follow your suggestion to add some tracing code, but I do not know how or what tracing code is. I am sure that is a good suggestion, however.

    While I do not know what triggers this anomaly, I have set break points and stepped through the code and I know that nothing is skipped or deviation in the path the code runs through.

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

    Re: DGV Column sometimes decides to not be visible.

    Given that we're not sure of the cause of the issue, I don't really know whether this will help or not but another option is to get rid of most of that code and do most of what's there in the designer. If you have added your DataSet to the form in the designer then bind it in the designer too. Add a BindingSource and bind your DataTable to that through the Properties window, then bind the BindingSource to your grid. That will add all the columns at design time and you can then hide those that you don't want to see there too. At run time, the only thing to do will be to populate the DataTable.

    You can also go part of the way instead. Add just the columns you want to see at run to the grid in the designer and set the DataPropertyName of each to the data source column you want it bound to. At run time, set AutoGenerateColumns to False and then set the DataSource. Those columns will be populated and no others created.

    By the way, you should always set the DataSource as late as you can. If you were to keep all the code you have, this part:
    vb.net Code:
    1. dgvSignList.DataSource = Me._MasterBase5_0DataSet
    2. dgvSignList.Height = 406
    3. dgvSignList.Width = 1035
    4. dgvSignList.DataMember = "lnkChangeApprove"
    should be changed to this:
    vb.net Code:
    1. dgvSignList.Height = 406
    2. dgvSignList.Width = 1035
    3. dgvSignList.DataMember = "lnkChangeApprove"
    4. dgvSignList.DataSource = Me._MasterBase5_0DataSet
    or this:
    vb.net Code:
    1. dgvSignList.Height = 406
    2. dgvSignList.Width = 1035
    3. dgvSignList.DataSource = Me._MasterBase5_0DataSet.lnkChangeApprove

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    I am assuming you are asking for the sequence of events
    You don't need to assume anything. You just have to answer the question I actually asked.
    What does that mean exactly? Are you clicking a Button in that form to reload the data? Opening that form repeatedly from somewhere else? Running the program repeatedly?
    Each one is a quite different thing to the others so which applies will cast a different light on the problem. Notice how I use terms like "reload" and "repeatedly"? I guess you were right to assume that I knew what that expression meant in general but, as you hadn't specified, I had no way to know exactly what it meant in this particular case. Nice try though.

    Quote Originally Posted by gwboolean View Post
    I do not know how or what tracing code is.
    Tracing is basically just following the state of the application during execution. Tracing code is just code like any other that provides output about the state of the application, e.g. writing to a text file. There is tracing functionality built into VS and .NET but now's probably not the time to go into the details, and I'm no expert on the subject. You can peruse the relevant documentation and the like on that at your leisure if you want.

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

    Re: DGV Column sometimes decides to not be visible.

    Also, exactly how are you opening and closing the form? I ask because whether it's the same instance or a different instance each time could also be relevant.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    You are probably right about working through the designer is a better choice. I have observed some other anomalies from using DGVs this way. Although I showed lnkChangeApprove as the DataMember, in another presentation lnkChangeTrain is the dataMember. Additionally, each table has two different presentations.

    Because of this the designer has neither a datasource nor a bindingsource defined in the Designer properties. I can see going ahead and defining the datasource in the designer (since that is the only one I use, but if I am presenting more than one table wouldn't defining a datamember in the designer cause a problem?

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    Because of this the designer has neither a datasource nor a bindingsource defined in the Designer properties. I can see going ahead and defining the datasource in the designer (since that is the only one I use, but if I am presenting more than one table wouldn't defining a datamember in the designer cause a problem?
    What you do in the designer just generates code that gets executed when the form is created. If you know that the initial state of the form will be the same every time then I'd suggest defining that initial state in the designer. It's much like you would set the initial Text on a Button even if you were likely to change that text later on. That's not to say that have to do that but it saves on writing boilerplate code.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    All are opened in the load event as shown below. The routines ending in Format() set form display properties and those ending in Load() are the ones for displaying the DGV. DocApproveAdminLoad() was the one I showed above.
    Code:
                Me.TblChangeRequestTableAdapter.FillByChangeID(Me._MasterBase5_0DataSet.tblChangeRequest, glbintChangeID)
                DocMasterFormat()
    Above is what is prior to the Cases in the load event. The query method is for the Change Request information that is displayed above the DGV.
    Code:
                    Case = 4
                        DocApproveTaskFormat()
                        DocApproveTaskLoad()
                    Case = 5 ' This not used
                        DocTrainTaskFormat()
                        DocTrainTaskLoad()
                    Case = 8
                        DocMasterFormat()
                        If glbintCount = 1 Then
                            DocApproveAdminFormat()
                            DocApproveAdminLoad()
                        ElseIf glbintCount = 2 Then
                            DocTrainAdminFormat()
                            DocTrainAdminLoad()
                        End If
    The form is closed with Me.Close()

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    You are probably right about working through the designer is a better choice. I have observed some other anomalies from using DGVs this way. Although I showed lnkChangeApprove as the DataMember, in another presentation lnkChangeTrain is the dataMember. Additionally, each table has two different presentations.
    Does this anomalous behaviour occur after changing the data source? Even if it's not relevant to this case, if you are changing the data source then I'd suggest that you set the DataSource to Nothing, Clear the Columns collection, then set the DataSource again. That will ensure that you have no extraneous columns left behind. Maybe you're already doing that but if not, it's probably a good idea.

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    All are opened in the load event as shown below. The routines ending in Format() set form display properties and those ending in Load() are the ones for displaying the DGV. DocApproveAdminLoad() was the one I showed above.
    Code:
                Me.TblChangeRequestTableAdapter.FillByChangeID(Me._MasterBase5_0DataSet.tblChangeRequest, glbintChangeID)
                DocMasterFormat()
    Above is what is prior to the Cases in the load event. The query method is for the Change Request information that is displayed above the DGV.
    Code:
                    Case = 4
                        DocApproveTaskFormat()
                        DocApproveTaskLoad()
                    Case = 5 ' This not used
                        DocTrainTaskFormat()
                        DocTrainTaskLoad()
                    Case = 8
                        DocMasterFormat()
                        If glbintCount = 1 Then
                            DocApproveAdminFormat()
                            DocApproveAdminLoad()
                        ElseIf glbintCount = 2 Then
                            DocTrainAdminFormat()
                            DocTrainAdminLoad()
                        End If
    The form is closed with Me.Close()
    That doesn't actually show the code that opens the forms.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    What you do in the designer just generates code that gets executed when the form is created. If you know that the initial state of the form will be the same every time then I'd suggest defining that initial state in the designer. It's much like you would set the initial Text on a Button even if you were likely to change that text later on. That's not to say that have to do that but it saves on writing boilerplate code.
    What I am understanding you are saying is that I should go ahead and set all of the properties in the Designer to, call it a default condition, which I could then change in my routines to fit the datamember and formatting needed at a specific condition?

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    You don't need to assume anything. You just have to answer the question I actually asked.
    I did. See my post 2.

    Tracing is basically just following the state of the application during execution. Tracing code is just code like any other that provides output about the state of the application, e.g. writing to a text file. There is tracing functionality built into VS and .NET but now's probably not the time to go into the details, and I'm no expert on the subject. You can peruse the relevant documentation and the like on that at your leisure if you want.
    OK.

    What you do in the designer just generates code that gets executed when the form is created. If you know that the initial state of the form will be the same every time then I'd suggest defining that initial state in the designer. It's much like you would set the initial Text on a Button even if you were likely to change that text later on. That's not to say that have to do that but it saves on writing boilerplate code.
    OK. However, there is no initial state of the form. There is the state of the form for which it is being used for a specific condition.

    Does this anomalous behaviour occur after changing the data source? Even if it's not relevant to this case, if you are changing the data source then I'd suggest that you set the DataSource to Nothing, Clear the Columns collection, then set the DataSource again. That will ensure that you have no extraneous columns left behind. Maybe you're already doing that but if not, it's probably a good idea.
    I use the same data source every time. What changes is the data member. The last time that the anomaly occurred I do not believe that I had changed the data member, but I am not sure, so that is certainly possible. I am not familiar with Clear the Columns Collection or how that is done.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    That doesn't actually show the code that opens the forms.
    Then be specific. What is the specific code you are asking for? To my knowledge the code that opens a form is what is contained in the load event.

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

    Re: DGV Column sometimes decides to not be visible.

    The best option is dependent on (as well as opinion) the specifics of the case. Let's say that you have a form that contains a DataGridView that can display data from table 1 and table 2. If the user can switch between the two at will then you're going to have to write code for both scenarios. In that case, you might prefer not to write both sets of code and configure the designer too, even if the form will always show data from table 1 first every time it loads. Then again, you might prefer to configure things in the designer if you know which table will load first, whether or not the user can switch back to that table after switching to the other. There's a number of factors to weigh up to determine which course of action you think is the best in any particular case.

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    Then be specific. What is the specific code you are asking for? To my knowledge the code that opens a form is what is contained in the load event.
    No, the form has to already have been opened in order for the Load event to be raised. What if you have no code in the Load event handler? Does that mean that the form isn't opened? The code that opens the form is the code that creates it, if indeed it is created explicitly, and then calls Show or ShowDialog.

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    Sounds like I need to weigh a number of factors and maybe take a little different approach to this then.

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    I use the same data source every time. What changes is the data member.
    I'm guessing that this may well have something to do with the issue. Instead of assigning the DataSet to the DataSource and the name of the DataTable to the DataMember, I'd suggest just assigning the DataTable to the DataSource, as shown in post #4. When switching between tables, do as suggested in post #10.

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    No, the form has to already have been opened in order for the Load event to be raised. What if you have no code in the Load event handler? Does that mean that the form isn't opened? The code that opens the form is the code that creates it, if indeed it is created explicitly, and then calls Show or ShowDialog.
    That is new to me, but OK, I believe that maybe we are getting somewhere. Here is the call for the form with the DGV. I also included the routines that surround the call. Possibly those might have something to do with the anomaly?

    Code:
                        glbobjWindowForm = Me
                        FormUpdate.DisableWindow()
                        frmSignTaskList.ShowDialog()
                        FormUpdate.EnableWindow()
    Code:
        Public Class FormControlRoutines
            Public Sub DisableWindow()
                'Reduce opacity of form and disable.
                With glbobjWindowForm.ActiveForm
                    .Opacity = 0.5
                    .Enabled = False
                End With
            End Sub
            Public Sub EnableWindow()
                frmChangeRequest.Activate()
                With glbobjWindowForm.ActiveForm
                    .Opacity = 1
                    .Enabled = True
                End With
            End Sub
        End Class

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    Code:
                        glbobjWindowForm = Me
                        FormUpdate.DisableWindow()
                        frmSignTaskList.ShowDialog()
                        FormUpdate.EnableWindow()
    Is what I've highlighted there a variable or a type.

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    What you highlighted is the form, frmSignTaskList.vb. It is not a variable.

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

    Re: DGV Column sometimes decides to not be visible.

    I just wanted to make sure that you didn't miss post #18 in all the back and forth. I won't post anything more until you've tested that because I have a sneaking suspicion that that may address the issue. If not, we can look further at that time.

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV Column sometimes decides to not be visible.

    OK, in #4 you have me simply move the the data source down below the size properties. I did this in the routine that uses the table lnkChangeApprove and the routine that uses the table lnkChangeTrain. I switched between the tables 3 times with no anomalies. I believe I am going to call it a night and continue with this in the morning. Since the original problem would manifest (occur) occasionally, I would not be able to say that this test with an N of 3 provides any kind of answer. I will also have to put things back as they were and run the same test to see if the anomaly occurs. But again, in the morning. Thanks.

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    OK, in #4 you have me simply move the the data source down below the size properties.
    No, not just that. The third snippet does just what I said in post #18:
    Instead of assigning the DataSet to the DataSource and the name of the DataTable to the DataMember, I'd suggest just assigning the DataTable to the DataSource

  25. #25
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by gwboolean View Post
    All are opened in the load event as shown below. ...
    In case you aren't aware, the Load event has an annoying problem that means it might hide exceptions from you.

    Either make sure you have exception handling in there to show you details of any exceptions, or (if apt) move the code to the Shown event instead.

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

    Re: DGV Column sometimes decides to not be visible.

    Quote Originally Posted by si_the_geek View Post
    In case you aren't aware, the Load event has an annoying problem that means it might hide exceptions from you.

    Either make sure you have exception handling in there to show you details of any exceptions, or (if apt) move the code to the Shown event instead.
    I considered that but post #3 said this.
    Quote Originally Posted by gwboolean View Post
    I have set break points and stepped through the code and I know that nothing is skipped or deviation in the path the code runs through.
    Now that I think about it though, that debugging was probably done on occasions that it worked correctly so that may yet turn out to be part of the problem. Mind you, given that the columns should be visible by default, you'd think that an exception in the `Load` event handler would cause extra columns to be shown rather than more to be hidden. Nothing else seems to make a lot of sense though, so it's certainly worth consideration.

Tags for this Thread

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