Inconsistent DataGridViewCell behavior

0
0

Hi,

I have a custom DataGridViewCell that works, but not quite!

On record selection the custom column in the the grid briefly flickers with the correct display (see attached with.png) and then reverts to a plain text column display (see attached without.png).  However, double clicking a cell in the the first column (which is a DataGridViewComboBoxColumn) causes the correct custom column to display!

The code is:

var docColumn = new DgvDocColumn() { Name = “colDocFile”, HeaderText = “Filename”, DataPropertyName = “Filename”, Width = 200 };
dataGridViewDocuments.Columns.Insert(1, docColumn);

public class DgvDocColumn : DataGridViewColumn
{
public DgvDocColumn()
{
CellTemplate = new DgvDocCell();
HeaderText = “Doc Column”;
Name = “docColumn”;
}

public sealed override DataGridViewCell CellTemplate
{
get { return base.CellTemplate; }
set { base.CellTemplate = value; }
}
}

public sealed class DgvDocCell : DataGridViewCell
{
private readonly Upload _add = new Upload { Width = 23, Text = “”, Dock = DockStyle.Fill };
private readonly Button _view = new Button { Width = 25, Text = “…”, Dock = DockStyle.Right };
public event Action<DgvDocCell, UploadedEventArgs> AddFile;
public event Action ViewFile;

public DgvDocCell()
{
_add.Uploaded += Add;
_view.Click += View;
}

public void ShowAdd()
{
this.Control = _add;
}

private void Add(object sender, UploadedEventArgs e) { if (AddFile != null) AddFile.Invoke(this, e); }
private void View(object sender, EventArgs e) { if (ViewFile != null) ViewFile.Invoke(this); }

protected override bool SetValue(object value)
{
if (value == null) this.Control = _add;
else this.Control = _view;
return base.SetValue(value);
}

protected override object GetValue()
{
if (base.GetValue() == null) this.Control = _add;
else this.Control = _view;
return base.GetValue();
}
}

It seems like a “timing” issue in rendering, and feels like I could fix by belatedly calling DataGridView.Paint() type method, but I haven’t been able to get the planets to align!

Thanks in advance for your assistance,
Neil.

Attachment
  • You must to post comments
0
0

Wisej-1.4.65 seems to have fixed the issue.  Many thanks!

  • You must to post comments
0
0

Here is a bare bones example … initially the custom column appears to be a text column – resizing columns causes the correct display.

  • You must to post comments
0
0

Could you please send a test case that we can run?

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.