Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Combobox as Celleditor

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Wed Apr 06, 2005 11:58 am    Post subject: Combobox as Celleditor Reply with quote

I have three questions.

1.)
In my program is it possible to change the datasource for a virtualtree.
When the datasouce will be changed then I have to add a different number of columns and I want to use for some column an editbox as celleditor and for some a combobox. But that is not the problem. The problem I have is to add items to the combobox. I try it in the way you can see in the code snippet below but the the displayed combobox don't show any Item which I have added.

I have added two CellEditors to the VirtualTree via the designer:
The CEEditBox which is a UniversalEditBox.
The CEComboBox which is a ComboBox.


Code:

//Each Parameter will generate a column
foreach(string s in xdm.samples.getParameterNameList().Values)
 {
   Column c = new Column();
   c.Name = s;
   c.Caption = s;
   Parameter p = this.dsm_browsing.Parameters[s] as Parameter;

   //It exists two kind of parameters.
   //For categorical parameter i want a combobox to select a value.
   if(p.IsCategorical)
   {
      this.cellEditor3Control.Items.Clear();
      foreach(PolymorphValue pv in p.PossibleValues.Values)
      {
         //cellEditor3Control is the combobox associated to the CEComboBox.
         this.cellEditor3Control.Items.Add(pv.ToString());
      }
      c.CellEditor = this.CEComboBox;
   }
   //For numerical I want a textbox as CellEditor
   else
      c.CellEditor = this.CEEditBox;

   //Now add the column to the VirtualTree
   VTExperimentDesign.Columns.Add(c);   
}
//Set the datasource
VTExperimentDesign.DataSource = this.xdm.samples;



2.)
When a cell is in the editmode and i change the datasource and the tree will redisplayed with new data from the new datasource then the CellEditor is still displayed from the previouse view until a row from the new tree is selected.



3.) Is it possible to configure the VirtualTree to deselect all row if I click in an empty space of the VirtualTree. This behaviour is standard in the windows forms Listview[/img]
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Apr 07, 2005 12:55 am    Post subject: Reply with quote

Some answers:

Q1) The editor control (cellEditor3Control) is just a template for the control(s) actually used by VirtualTree to do the editing - it is not the actual control used. The reflection mechanism used to copy the properties of the template control can cope with most common properties - but the list of items for combo box is beyond its capabilities.

For this reason we provide a separate mechanism to allow you to initialise more complex properties such as this. Add a handler to the CellEditor.InitializeControl event. This is fired prior to the control being displayed - and gives you a chance to initialize properties. The editor controls are cached and reused for performance so this also gives you a chance to reset properties to the defaults if necessary eg:

Code:


//Each Parameter will generate a column
foreach(string s in xdm.samples.getParameterNameList().Values)
 {
   Column c = new Column();
   c.Name = s;
   c.Caption = s;
   Parameter p = this.dsm_browsing.Parameters[s] as Parameter;

   //It exists two kind of parameters.
   //For categorical parameter i want a combobox to select a value.
   if(p.IsCategorical)
   {
       ComboBox comboBox = new ComboBox();
       comboBox.Tag = p;
       c.CellEditor = new CellEditor(comboBox);
       c.CellEditor.InitializeControl += new CellEditorInitializeHandler(OnInitializeComboControl);
   }
   //For numerical I want a textbox as CellEditor
   else
      c.CellEditor = this.CEEditBox;

   //Now add the column to the VirtualTree
   VTExperimentDesign.Columns.Add(c);   
}

private void OnInitializeComboControl(object sender, CellEditorInitializeEventArgs e)
{
    ComboBox comboBox = (ComboBox)e.Control;
    if (e.NewControl)
    {
       Parameter p = comboBox.Tag as Parameter;
       foreach(PolymorphValue pv in p.PossibleValues.Values)
       {
          comboBox .Items.Add(pv.ToString());
       }
    }
}


Note that (if I understand your code correctly) you should be creating a new instance of a combobox control and editor for each column since the editor for each column requires a different set of values.
I'm using the tag parameter of the combo control to pass the contextual information required.

An alternative to this whole approach is to define a TypeConverter for your Parameter type that provides a list of standard values. You can then use a standard UniversalEditBox as your editor and it will display the selection for you automatically - this in my opinion would be much cleaner. The code below illustrates a simple type converter for displaying some standard values for an integer type:

Code:

public class MyConverter : TypeConverter
{
    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
        return true;
    }

    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
        int[] values = { 1,4,6 };
        return new StandardValuesCollection(values);
    }
}


Q2) This appears to be a bug - we will fix this ASAP. You can work around it if you derive a class from VirtualTree and override the DataSource property as follows:

Code:

public override object DataSource
{
    get { return base.DataSource; }
    set
    {
        this.EditWidget = null;
        base.DataSource = value;
    }
}


Q3) I assume here you mean the empty space (if any) below the tree contents. We will add this as a feature request.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Thu Apr 07, 2005 9:43 am    Post subject: Reply with quote

Thank for your awnser.
But there is a problem in your solution.

When the OnInitializeComboControl method is called, there is no object in the Tag property of the e.Control. I have tested to set the name property of the ComboBox to "test", but this will also be lost and in the EventHandler the name of the e.control is an empty string.

I have debugged the code: The Tag property are assigned correctly to the but in the eventhandler ist it null.

I'm interested to in your alternative approach, but I don't understand where and how I have to use the TypeConverter and how can act a UniversalTextBox as ComboBox.
Sorry Sad


PS: You have great Control and a very good Support.
My company will buy your control.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Apr 07, 2005 10:09 am    Post subject: Reply with quote

Try the following code instead (sorry I couldn't really test it beforehand):

Code:

private void OnInitializeComboControl(object sender, CellEditorInitializeEventArgs e)
{
    CellEditor cellEditor = sender as CellEditor;
    ComboBox comboBox = (ComboBox)e.Control;
    if (e.NewControl)
    {
       Parameter p = cellEditor.Control.Tag as Parameter;
       foreach(PolymorphValue pv in p.PossibleValues.Values)
       {
          comboBox .Items.Add(pv.ToString());
       }
    }
}


This gets the tag from the original template control.

Using type converters is actually fairly simple. They are a standard .NET mechanism used for converting types to strings and back and are used by the property grid to allow display and editing of types in the Visual Studio property pane.

To associate a type converter with a type simply add an attribute as shown:

Code:

[TypeConverter(typeof(MyTypeConverter))]
class Parameter
{
}


Now if you return a value of type Parameter for a cell value and set the editor for that column to be a UniversalEdit box - then the UniversalEdit box will use the type converter to display the value (and allow selection from the set of standard values). You can also set the TypeConverter to be used explicity in the GetCellData event/method.

Experiment first with a UniversalEditBox on a form and setting the Value property to variables of different types with TypeConverters to see what can be done (eg DateTimes, Colors, Images etc)
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Thu Apr 07, 2005 10:33 am    Post subject: Reply with quote

Thank you very much.

The code work.
But I think there is bug.

If I click at first a item with a combobox the the combobox shows that it have the number of entries I would expect but they are unvisible.
I can select the entries and the text of the combobox change also I would expect. But then when I click a item in column with a UniversalEditBox and then back to the item with a combobox every think is fine. From this point of time the combobox work's correctly.

I will also play with the alternative approach but maybe this ist a bug you interested in.

Cheers salomo
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Apr 07, 2005 10:46 am    Post subject: Reply with quote

This sounds very strange. Any chance you could send a cut down project that exhibits this problem to support@infralution.com (or at least some screen captures so we can see exactly what is happening). I have used combo boxes initialised in this way in other projects without encountering any problems.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Thu Apr 07, 2005 11:53 am    Post subject: Reply with quote

I have tested my application on other (naked) system, but there was no problem with combobox. I guess this effect is related to some other problems which are desribed by the user "cristi_ursachi" in the topic "icons on XP" and I can observe to on my development system.

1.) the MessageBox with trial version information appear without text
2.) Icons with blackboxes. I have blackbox in the rowheader where normally appears the black arrow for the selected row.


I think it's a problem of the OS and or the .net framework.
I have enabled/disabled Visual Styles in my application.
I have enablled/disabled Luna on my XP.

No effect Sad

At first tested the VirtualTree I could observ this effect sporadic.
Sometimes trial version messagebox with tetxt sometimes without.
Now is the effect permanently. It's very confusing. But I don't think it is a problem of the control. I think it is a more generally problem.

If you have any ideas I will test it.
If I have found a solution I will post it.

Cheers salomo
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Apr 08, 2005 6:24 am    Post subject: Reply with quote

It does sound like an OS/Framework issue.

I've just realized there is yet another way to handle initializing combo box values which may be somewhat easier. If you set the DataSource property of the combo box this is copied from the template control (unlike the Items property). So the following will also work:

Code:

//Each Parameter will generate a column
foreach(string s in xdm.samples.getParameterNameList().Values)
 {
   Column c = new Column();
   c.Name = s;
   c.Caption = s;
   Parameter p = this.dsm_browsing.Parameters[s] as Parameter;

   //It exists two kind of parameters.
   //For categorical parameter i want a combobox to select a value.
   if(p.IsCategorical)
   {
       ComboBox comboBox = new ComboBox();
       comboBox.DataSource = p.PossibleValues.Values;
       c.CellEditor = new CellEditor(comboBox);
   }
   //For numerical I want a textbox as CellEditor
   else
      c.CellEditor = this.CEEditBox;

   //Now add the column to the VirtualTree
   VTExperimentDesign.Columns.Add(c);   
}


Ensure that you remove the InitializeControl handler - otherwise the CellEditor will call that - and not copy the template control properties for you.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Fri Apr 08, 2005 6:56 am    Post subject: Reply with quote

Sorry, But it does not not work.
Some extra info, the type of p.PossibleValues is SortedList.


I have played with thr UniversalEditBox. It's very cool to set the value to a DateTime or a Color. But I found no way to let the UniversalBox act like a combobox. If I set the Value property to a string[]. then get a String Collection Editor.

Cheers Jan
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Apr 08, 2005 7:08 am    Post subject: Reply with quote

When you say it doesn't work - do you mean you get an error - or that the values are not displayed in the combo box? If the values aren't being displayed in the combo box make sure that you have removed your InitializeControl handler. It's a bit hard to be definitive here because I don't have your code. I'll try to put together a simple sample that illustrates doing this.

Have a look at the ADODB Browser sample. The dropdown boxes for selecting the model are in fact UniversalEditBoxes displaying an enumeration. If you put a UniversalEditBox on a form and set the value to an enumeration you will see what I mean:

Code:

public enum Model
{
    Holden,
    Ford,
    Mazda
}

_editBox.Value = Model.Holden;


You can get this same behaviour for non-enum types by defining a TypeConverter which provides standard values (see earlier post)
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Fri Apr 08, 2005 7:33 am    Post subject: Reply with quote

Ok, I had only removed the body of the event handler.
Now it works.

Ok. the Enum example works.
I will try to implement a TypeConverter for my Parameter class.

Thanx
Back to top
View user's profile Send private message
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Fri Apr 08, 2005 7:56 am    Post subject: Reply with quote

Some problem with TypeConverter.

I have played with the TypeConverter, but I found no way fill the StandardValuesCollection dynamically. I can only fill the StandardValuesCollection with a static list of values. But I need a different lista of values for each instance of Parameter.

Is it generally possible to do that?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Apr 08, 2005 8:03 am    Post subject: Reply with quote

If you have different allowable values for each instance of Parameter then you would probably be better sticking with setting the DataSource of a normal ComboBox.
_________________
Infralution Support


Last edited by Infralution on Fri Apr 08, 2005 8:10 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
salomo



Joined: 05 Apr 2005
Posts: 13
Location: Potsdam (Germany)

PostPosted: Fri Apr 08, 2005 8:07 am    Post subject: Reply with quote

Thanx a lot for your help to starting with VirtualTree in my application.

Again, Very good support Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group