Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Need to change value of a cell which is an object.

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Need to change value of a cell which is an object.
Link Posted: 08-Dec-2005 01:58
Hello!

We use DynamicallyAutoDetectDataTypeColumn class for our grid.

I will try to be very specific and accurate so you don't misunderstand our problem that's why the letter is rather long.

We have some problem that I hope that you out there can help us with.
I have looked at the sample code which has
helped us a lot but we still have some problem because we don't know how to use the FlyGrid to fulfil our solution.
There is no sample code that give any hint about how to solve our problem.

Here is how we use the FlyGrid.
Each cell in a FlyGrid is an object of class GridValue and we store these objects in the Rows.DataSource.
This works fine. A cell is a specific row and column for example row 2 and column 2. Node that we use the grid cellbased. So we don't look at the grid as column oriented which almost all sample code does.
Before we store the object of GridValue into Rows.DataSource we set some datamember such as
value, maxAllowedValue, minAllowedValue and numberOfDecimal.
Once maxAllowedValue, minAllowedValue and numberOfDecimal
is set in the object they will never be changed by the user of the application.

Here a basic GridValue class definition showing the important datamembers.
public class GridValue
{
    double value;
    double maxAllowedValue;
    double minAllowedValue;
    double numberOfDecimal;
}

Here is an example of one of our grid
No      o2      N2      Ar_p
=============================
1       100.7   33.55   5.5
2       66.31   66.3    1.73
3       31.1     95.9    7.3

Here an example.
In the figure above each cell is actually an object of GridValue and each object of GridValue contains the value
according to the figure above in addition to maxAllowedValue, minAllowedValue, and numberOfDecimal.

Now to our core problem. Assume we want to change the value 95.9 for an object that exist in the Rows.DataSource to 96.

Assume that this object contains 110 for maxAllowedValue and  
0 for minAllowedValue and 1 for numberOfDecimal and of course 95.9 for value that we want to change to 96.

When we double klick and change the 95.9 to 96 we only change the value we never change any value for
maxAllowedValue or minAllowedValue or numberOfDecimal.

We have overridden method ConvertFrom
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value){...}
but when we do so we lose all the important information that exist in our object of class GridValue such as maxAllowedValue, minAllowedValue and numberOfDecimal because there is no way to find this information when the ConvertFrom method is called.

So we think to override this ConvertFrom will not solve our problem.
We hope that this FlyGrid has some good methods to use to solve our problem.
If we in some way could get the maxAllowedValue and minAllowedValue and numberOfDecimal from the object then we could just pass these values to the constructor when creating the GridValue
object in the ConvertFrom method.

The problem that I have mentioned here is a basic requirement that we have and must be solved.


Below is just the overridden ConvertFrom method in our GridValue class

This overridden ConvertFrom method is called when changing a value in the flygrid. As you can see here a new
GridValue object is instansiated so here we would like to have access to
maxAllowedValue, minAllowedValue and numberOfDecimal. But I assume it's impossible in this method.

public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
  if (value is string)
    return new GridValue( Convert.ToDouble( value ) );
  return base.ConvertFrom(context, culture, value);
}


Please refer to some code that you might have somewhere.

Many thanks in advance.


//Tony
Link Posted: 08-Dec-2005 14:43
In the nearest FlyGrid.Net update you can use ITypeDesciptorContext provided by AutoDetectDataTypeColumn as argument in the TypeConverter. ConvertTo/ConvertFrom methods to obtain original value of GridValue.
In this case your convertion will looks like following:
[C#]
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
   if (value is string)
   {
     if (context != null && context.Instance != null)
     {
       GridValue originalGridValue = context.Instance as GridValue;
       if (originalGridValue != null)
       {
         originalGridValue.Value = Convert.ToDouble( value );
         return originalGridValue;
       }
     }
     return new GridValue( Convert.ToDouble( value ) );
   }
   return base.ConvertFrom(context, culture, value);
}