View previous topic :: View next topic |
Author |
Message |
Matthys
Joined: 23 Nov 2007 Posts: 4
|
Posted: Fri Nov 23, 2007 12:51 pm Post subject: TypeConverter.GetStandardValues |
|
|
Hello,
I am implementing a TypeConverter to use in VirtualTree.
In my TypeConverter I override ,
Code: | StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) |
, however when VirtualTree calls the GetStandardValues() method in my TypeConverter the context variable is received as 'null'.
This is not what I expect to happen, since I would like to return standard values based on the Instance of the value I am converting/editing.
Is it correct to receive the context as a 'null' value? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Nov 23, 2007 9:55 pm Post subject: |
|
|
If you look at the MSDN documentation for TypeConverter.GetStandardValues you will see it says the following:
Quote: | context
An ITypeDescriptorContext that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be a null reference (Nothing in Visual Basic). |
Currently the UniversalEditBox calls the overloaded parameterless version of TypeConverter.GetStandardValues() - which calls the method you are overriding with null for the context parameter to indicate the default context should be used.
So if the list of values you wish to display is not constant then you may need to look at an alternative approach. I can see two possibilities:
The first is to use a standard combo box and set the DataSource programmatically (see other threads on this forum about using combo boxes as editors).
The second is to provide a constructor for your custom TypeConverter that takes some parameter (for instance the column) that determines the StandardValues that will be returned. Then handle the GetCellData event to programmatically set the CellData.TypeConverter eg
Code: | private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
// get the default binding for the given row and use it to populate the cell data
//
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
if (e.CellData.Value is MyType)
{
e.CellData.TypeConverter = new MyTypeConverter(e.Column);
}
} |
_________________ Infralution Support |
|
Back to top |
|
|
Matthys
Joined: 23 Nov 2007 Posts: 4
|
Posted: Mon Nov 26, 2007 7:27 am Post subject: |
|
|
Thank you very much. |
|
Back to top |
|
|
|