Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is it possible to modify the Columns property of a DataGridView (DGV) on a derived UserControl if the DGV has been defined on the 'base' UserControl?

Posted on 2011-09-23
4
Medium Priority
?
453 Views
Last Modified: 2013-11-27
I am trying to modify the columns of a DataGridView on a custom UserControl, call it UC_x, which derives from another custom UserControl, call it UC_base (i.e., UC_x : UC_base).  The DataGridView has been placed onto UC_base in the Designer and has its 'Modifiers' property set to 'Protected Internal'.

When I open the derived UserControl, UC_x, in the Designer I see the DataGridView but I do not have access to the Columns property of the DataGridView - it is grayed-out in the Properties window - and the arrow that normally appears at the upper-right corner of a DataGridView that allows me to edit the columns (add, remove, rename, etc.) does not appear either.  My goal was to create several UserControls - UC_x, UC_y, UC_z, etc. - that would all derive from UC_base and all of which would have different columns.  However that does not look possible.

While investigating this issue I placed a TextBox onto UC_base and set its 'Modifiers' property to 'Protected Internal'.  On UC_x I can modify the Text property of the TextBox.  Other properties, e.g., the name of the TextBox, are grayed-out.  This implies to me that all objects placed onto the base UserControl will have some properties that are accessible by a derived UserControl and some that are not.  If this model is correct, it appears that for a DataGridView all properties, including the Columns property, fall into the group of properties that are not accessible from a derived UserControl.

Is there any way for the Columns property of a DataGridView on a derived UserControl to be modified - columns removed, columns added, columns renamed, etc.?  If not, what are some suggested alternatives?

I have considered simply adding columns programmatically in the derived UserControls.  Any thoughts on this?

I am writing a C# application using Microsoft Visual Studio 2010.
0
Comment
Question by:e_livesay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36599444
If you are looking to access Protected Internal from the designer, then you will hit a fairly solid brick wall.  You can provide your own custom GridColumns property, and hide the Columns property.
0
 

Accepted Solution

by:
e_livesay earned 0 total points
ID: 36713586
I appreciate the reply.  That was quite a solid brick wall.

I have gotten past this problem by adding columns programmatically in the derived UserControls.  That is, the base UserControl has a DataGridView on it which does not have any Columns in it and each of the derived UserControls have a routine in them that adds Columns to the DataGridView programmatically.

I'm unsure what I'm supposed to do with the points associated with this question.  As I said, I appreciate your feedback - especially since no one else commented at all - but I ended up solving this problem by using a method that I suggested in the question itself and not by adding a custom GridColumns property.  What is the protocol for this?

Thanks.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36717107
The protocol is "it depends".  If you think that I helped, by confirming your suspicions, then I would accept my answer.  If it was a lame response that didn't help you very much, then I would suggest either accepting your answer as the solution or requesting attention to this question, and asking for a delete.

No skin off my nose either way--I am just here to help, where I can...
0
 

Author Closing Comment

by:e_livesay
ID: 36923048
This was solved by adding columns to the DataGridView programmatically which was suggested in the question itself.

TheLearnedOne - thanks for your comment and the suggestion regarding what to do regarding the points associated with this question.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question