Custom control in DataGridViewColumn

0
0

Hi guys,
I’m trying to do something along the lines of this thread,
https://wisej.com/support/question/how-do-i-add-a-custom-control-to-a-data-grid-view
However, the samples in the answers do not work anymore in 3.2.1 (the question is since 2018). In particular, in the overriden SetValue I get a null exception at the point indicated in the following snipet.

If I remove the SetValue altogether, to get around the problem, the cells of the relevant column show up empty. It looks like somehow this.Control is reset to null.

What is the updated version for this?
Best,
Alex

public class DatagridViewProgressBarCell : DataGridViewCell
{
public DatagridViewProgressBarCell()
{
this.Control = new ProgressBar() {
Dock = DockStyle.Fill
};
}

protected override bool SetValue(object value)
{
((ProgressBar)this.Control).Value = (int)value;     // <<==== this.Control is null
return base.SetValue(value);
}

}

  • You must to post comments
0
0

Hi Alex,

I have attached a sample to steer you in the right direction!.

It’s not a bug per se, but it is an enhancement that will be included in a future release!

Basically, you’ll need to override the Clone() method of the DataGridViewCell and assign your control there!

HTH,
Alaa

  • Alex Prinias
    Hi Alaa, thanks for that. However, when I run your attached application, I keep seeing the same behaviour, a Null Exception at this line ((ProgressBar)this.Control).Value = (int)value; of the SetValue method. this.Control is still null. The debugger shows that it never goes through the Clone() method. Unless you mean I should wait for the new release. Alex.
  • You must to post comments
0
0

Hi Alex,

I could reproduce what you reported and we´ll check in detail what changed here.
We´ll get back to you asap.

Best regards
Frank

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.