[RESOLVED] DataGridView Properties-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] DataGridView Properties

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    342

    Resolved [RESOLVED] DataGridView Properties

    I keep finding more and more things that I end up having to set properties in the code, rather than in the properties window.

    For a lot of forms I like to use groupbox containers. I understand that anything placed into a container adopts the containers property settings, just as the container adopts the form property settings. However, I generally like to set the groupbox property settings to what I like, and I might well set the property settings of any controls in the groupbox to something completely different. When executing the form I have never had any problems with the property settings of the controls in the groupbox......... with one friggin exception. DGVs!!!!

    Overtime, I have found that some of the properties of the DGV will randomly change to the groupbox property settings. Well, actually only one. The Default Cell Style properties. What occurs is that this property will randomly revert to the combobox property settings. When I say randomly I mean that the form will execute flawlessly for awhile, then on an execution the property reversion occurs. Which brings me back to setting the properties in the code rather than the DGV properties window. So here is what the DGV properties window looks like:

    Name:  DGV.jpg
Views: 155
Size:  74.8 KB

    So I have placed the settings for each of the properties, but seem to be unable to figure out how to set one of them. As can be seen, there is nothing for the font setting, which by the way I want to be, Times New Roman, 11.25pt. I have tried fill that a number of different ways, but am unable to come up with the combination that works. Can anyone give me a lift here?

    Code:
            With dgvItemList
                .DefaultCellStyle.Font =
                .DefaultCellStyle.ForeColor = Color.Black
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
            End With

  2. #2
    Hyperactive Member Mike Storm's Avatar
    Join Date
    Jun 2017
    Location
    Belgium
    Posts
    425

    Re: DataGridView Properties

    Replace font name to what ever font you want

    Code:
    .DefaultCellStyle.Font = New Font("Tahoma", 11)

  3. #3
    Hyperactive Member Mike Storm's Avatar
    Join Date
    Jun 2017
    Location
    Belgium
    Posts
    425

    Re: DataGridView Properties

    By the way, if all your datagridview have the same properties, under a module you can create a sub to configure them.

    Code:
    Public Sub MyDGV_STYLE(DGV as DataGridView)
    
    With DGV
                .DefaultCellStyle.Font = New Font("Tahoma", 11)
                .DefaultCellStyle.ForeColor = Color.Black
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
    End With
    
    End Sub
    You call it under the load Event containing the DatagridView

    Code:
     MyDGV_STYLE(YourDGV)
    Reamember you passing the DGV as control/object so its without ""

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    342

    Re: DataGridView Properties

    Mike,

    Thanks. You know, I am starting to see a pattern with some of these property settings, when done in the code. Also, I can tell you are a Tahoma man.

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.