user control with a datagridview
-
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. -
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.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:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)
-
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:▒▒〓▒〓▒▒ :^):^):^):^):^):^):^):^):^):^):^):^)