tags:

views:

80

answers:

2

I'm struggling getting a certain column within my DataGridView to display things right. It had been working and I must have broken something subtly, now all I get is an empty string. Does anyone know why this might be?

// this inherits from DataGridView
this.Rows.Add(new object[] 
{
    "test",
    new CustomType("A", "1")
});

CustomType()
{
   ...
   public override String ToString()
   {
      return this.String1 + ":" + this.String2;
   }
}

The result of such a thing is my Row.Cells[1].Value is "A : 1". However the FormattedValue is always blank...

A: 

I can't tell if your way is incorrect, but you seem to be doing it differently than the API reference for DataGridView.FormattedValue would suggest.

Did you try it that way?

John at CashCommons
@John : That page is using the 'FormattedValue' and parsing the result just to update an aggregated label. It isn't detailing about adding rows to the DataGridView.
Ian
A: 

Ok, I managed to find the cause of this... Unfortunately it was an annoying designer change whereby it lost the information that the column was bound to when I removed a different control from there.

This means that the databinding was not set, and hence it didn't know how to display the value.

Ian