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. C#
  4. user control with a datagridview

user control with a datagridview

Scheduled Pinned Locked Moved C#
helpcss
3 Posts 2 Posters 1 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.
  • Z Offline
    Z Offline
    zwan13
    wrote on last edited by
    #1

    I'm developing a user control which is build with a datagridview, and others controls. When I use this control in my application at desing time, I'd like to access de properties of the datagridview embebed in my control to add columns. I've created a public property to expose de grid, something like this: private System.Windows.Forms.DataGridView _grid; [Description("Description"), Category("mycategory"), EditorBrowsable] public System.Windows.Forms.DataGridView Grid { get { return _grid; } set { _grid = value; } } My problem is that I can't access the Columns property at desing time (In the property editor. I get this error: Object reference not set to an instance of an object. Then I decide to expose a property for the datagrid columns: [Description("My Description"), Category("MyCategory"), EditorBrowsable] public DataGridViewColumnCollection MyColumns { get { return this.grid1.Columns; } } Now I've binded the grid to a TableDataAdapter returned by a Web Sevice. My problen now is when I add a new column, the column is not show at execution time. (At desing time I can see the column added). I think that in execution time the grid executes the databinding and rewrites my added column. The same happens if I want to hide one of the columns returned by my Web Service, in execution time the column is visible. Perhaps doing it programatically I could add and hide columns , but I want to do it the easiest possible for de developers who are going to use this control. Thanks.

    X 1 Reply Last reply
    0
    • Z zwan13

      I'm developing a user control which is build with a datagridview, and others controls. When I use this control in my application at desing time, I'd like to access de properties of the datagridview embebed in my control to add columns. I've created a public property to expose de grid, something like this: private System.Windows.Forms.DataGridView _grid; [Description("Description"), Category("mycategory"), EditorBrowsable] public System.Windows.Forms.DataGridView Grid { get { return _grid; } set { _grid = value; } } My problem is that I can't access the Columns property at desing time (In the property editor. I get this error: Object reference not set to an instance of an object. Then I decide to expose a property for the datagrid columns: [Description("My Description"), Category("MyCategory"), EditorBrowsable] public DataGridViewColumnCollection MyColumns { get { return this.grid1.Columns; } } Now I've binded the grid to a TableDataAdapter returned by a Web Sevice. My problen now is when I add a new column, the column is not show at execution time. (At desing time I can see the column added). I think that in execution time the grid executes the databinding and rewrites my added column. The same happens if I want to hide one of the columns returned by my Web Service, in execution time the column is visible. Perhaps doing it programatically I could add and hide columns , but I want to do it the easiest possible for de developers who are going to use this control. Thanks.

      X Offline
      X Offline
      xibeifeijian
      wrote on last edited by
      #2

      Just change "private System.Windows.Forms.DataGridView _grid;" to private System.Windows.Forms.DataGridView _grid=new DataGridView();:rolleyes:

      :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

      Z 1 Reply Last reply
      0
      • X xibeifeijian

        Just change "private System.Windows.Forms.DataGridView _grid;" to private System.Windows.Forms.DataGridView _grid=new DataGridView();:rolleyes:

        :^):^):^):^):^):^):^):^):^):^):^):^) :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::^):^):^):^)▒▒〓▒〓▒▒ :^):rose::^):^):^):^)▒〓〓〓〓〓▒ :^):rose::rose::rose::rose::rose:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)

        Z Offline
        Z Offline
        zwan13
        wrote on last edited by
        #3

        I forgot to post that I've an instance of the grid (In the code behind): this.grid1 = new Mycontrols.Controles.Grid(this.components); So that is not the problem. Thank you. -- modified at 10:52 Sunday 3rd June, 2007

        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