Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Changing default value of a property of a control (DataGridView).

Changing default value of a property of a control (DataGridView).

Scheduled Pinned Locked Moved Visual Basic
csharpvisual-studiocsswinforms
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    priyamtheone
    wrote on last edited by
    #1

    I am inheriting my own datagridview (say MyDataGridView) from the standard datagridview control. What I want is that certain properties of MyDataGridView should have a different default value than what its base have. For example, AllowUserToAddRows, AllowUserToDeleteRows, AllowUserToResizeRows properties should have the default values of False; so that when I drag MyDataGridView into a form in the IDE, the default values shown in the properties grid should be False. Later on, if I want to change them to True from the grid, they will be set accordingly. Is it possible somehow? Please note that I don't want to set the default value of any custom property in MyDataGridView but the properties mentioned above that are derived from the base. Thanks. VS.Net, Framework 4.0, VB.Net, C#.Net, WinForms

    S W 2 Replies Last reply
    0
    • P priyamtheone

      I am inheriting my own datagridview (say MyDataGridView) from the standard datagridview control. What I want is that certain properties of MyDataGridView should have a different default value than what its base have. For example, AllowUserToAddRows, AllowUserToDeleteRows, AllowUserToResizeRows properties should have the default values of False; so that when I drag MyDataGridView into a form in the IDE, the default values shown in the properties grid should be False. Later on, if I want to change them to True from the grid, they will be set accordingly. Is it possible somehow? Please note that I don't want to set the default value of any custom property in MyDataGridView but the properties mentioned above that are derived from the base. Thanks. VS.Net, Framework 4.0, VB.Net, C#.Net, WinForms

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      Have a try of this

      Public Class Class1
      Inherits DataGridView

      Private \_AllowUserToAddRows As Boolean = False
      
      Public Shadows Property allowUserToAddRows() As Boolean
          Get
              Return \_AllowUserToAddRows
          End Get
          Set(ByVal value As Boolean)
              If \_AllowUserToAddRows <> value Then
                  \_AllowUserToAddRows = value
                  MyBase.AllowUserToAddRows = value
              End If
          End Set
      End Property
      

      End Class

      Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

      P 1 Reply Last reply
      0
      • P priyamtheone

        I am inheriting my own datagridview (say MyDataGridView) from the standard datagridview control. What I want is that certain properties of MyDataGridView should have a different default value than what its base have. For example, AllowUserToAddRows, AllowUserToDeleteRows, AllowUserToResizeRows properties should have the default values of False; so that when I drag MyDataGridView into a form in the IDE, the default values shown in the properties grid should be False. Later on, if I want to change them to True from the grid, they will be set accordingly. Is it possible somehow? Please note that I don't want to set the default value of any custom property in MyDataGridView but the properties mentioned above that are derived from the base. Thanks. VS.Net, Framework 4.0, VB.Net, C#.Net, WinForms

        W Offline
        W Offline
        Wayne Gaylard
        wrote on last edited by
        #3

        You just need to set the relevant properties in the constructor of you custom control like this:-

        Public Class MyDataGridView
        Inherits DataGridView

        Public Sub New()
            InitializeComponent()
            AllowUserToAddRows = False
            AllowUserToDeleteRows = False
        End Sub
        

        End Class

        When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

        1 Reply Last reply
        0
        • S Simon_Whale

          Have a try of this

          Public Class Class1
          Inherits DataGridView

          Private \_AllowUserToAddRows As Boolean = False
          
          Public Shadows Property allowUserToAddRows() As Boolean
              Get
                  Return \_AllowUserToAddRows
              End Get
              Set(ByVal value As Boolean)
                  If \_AllowUserToAddRows <> value Then
                      \_AllowUserToAddRows = value
                      MyBase.AllowUserToAddRows = value
                  End If
              End Set
          End Property
          

          End Class

          Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

          P Offline
          P Offline
          priyamtheone
          wrote on last edited by
          #4

          I tried the following way as well as yours on the Visible property of an inherited label but yet it stays True in the properties grid when compiled and dragged in the IDE. I need to change it manually to take effect.

          Imports System.ComponentModel

          Public Class MyLabel
          Inherits Label

          Public Sub New()
              MyBase.New()
          
              'This call is required by the Component Designer.
              InitializeComponent()
          End Sub
          
           \_
          Public Shadows Property Visible As Boolean
              Get
                  Return MyBase.Visible
              End Get
              Set(ByVal value As Boolean)
                  MyBase.Visible = value
              End Set
          End Property
          

          End Class

          Another point is, I tried both ways on the AutoSize property too, with the default value of False. In that case though, in the properties grid, it was showing False but actually the property remains True, as that's what I can see while executing. In order to set the value to False, I need to set it to True and then back to False again. :sigh:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups