I have following situation:
class TextBoxCellControl : TextBox, IDataGridViewCellControl
class EnhancedTextBoxCellControl : Panel, IDataGridViewCell
{
private TextBox encapsulatedTextBox;
private Button button;
...
}
class DataGridViewCell
{
private IDataGridViewCellControl cellControl;
void foo()
{
TextBox tb = cellControl as TextBox;
if (tb != null) { do something }
}
}
Class TextBoxCellControl and DataGridViewCell are out of my control and I need EnhancedTextBoxCellControl to inherit from Panel.
Is there some solution to this situation so EnhancedTextBoxCellControl could emulate TextBox which it encapsulates? Isn’t possible somehow react to the cast to TextBox and return encapsulatedTextBox instead of this (Sort of duck typing cast)?
No, this is not possible since B must inherit from Panel and C’s implementation is private.
Your only real choice is to inherit from C and perform your own logic in your inherited class’ constructor.