View previous topic :: View next topic |
Author |
Message |
medbiller
Joined: 20 Dec 2007 Posts: 39 Location: Arroyo, PR
|
Posted: Sun Jul 08, 2012 8:14 pm Post subject: DrawItem event won't fire for vTree ComboBox cell editor |
|
|
Hi. I'm using a ComboBox cell editor in my virtual tree(vTree). It works fine setting it up in the GetCellData event handler. I can change DropDown width & height. I cannot make the DrawItem event to fire so as to change Font, Styles, Colors, etc. of the items listed in the DropDown portion. I've tried,
1. Defining the combobox to bind in GetCellData at the module level making it Public & wiring the DrawItem event to it using code (AddHandler...) after binding in GetCellData.
2. Dragging a ComboBox on the form, setting the DrawItem in VS2010 & binding it in GetCellData. Also using AddHandler...
3. Using the ComboBox created by VTree directly named ComboBox1 in all of the above fashions.
I just can't make the DrawItem event fire. Otherwise the ComboBox is working as expected. Of course I'm setting (What ever combobox I use).DrawMode = DrawMode.OwnerDrawFixed & .DropDownStyle = ComboBoxStyle.DropDown both by code in GetCellData & setting it in the property grids (design time). I'm using vTree 4.1.2 and VB2010 and .Net 4.0 with Windows 7. Thanks. _________________ Medical billing & records developer. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jul 09, 2012 1:08 am Post subject: |
|
|
The editor control that you create at design time is a template for the editor controls that Virtual Tree will create at runtime as required. Virtual Tree will automatically copy most simple properties that are set on the design time template control when it initializes the actual controls that it uses at runtime. More complex properties and event handlers however cannot be copied from the template control. To intialize complex properties or add event handlers to editor controls you must handle the CellEditor.InitializeControl event. This event is fired each time Virtual Tree displays a new Cell Editor control and can be used to initialize control properties or add event handlers to the control eg
Code: | private void comboEditor_InitializeControl(object sender, CellEditorInitializeEventArgs e)
{
if (e.NewControl)
{
ComboBox comboBox = (ComboBox)e.Control;
comboBox.DrawItem += new DrawItemEventHandler(comboBox_DrawItem);
}
} |
_________________ Infralution Support |
|
Back to top |
|
|
medbiller
Joined: 20 Dec 2007 Posts: 39 Location: Arroyo, PR
|
Posted: Mon Jul 09, 2012 11:06 am Post subject: cboCellEditor_InitializeControl is not firing eithe. |
|
|
I've added the following & the program never stops in any of this SUBS.
Private Sub cboCellEditor_InitializeControl(sender As Object, e As Infralution.Controls.VirtualTree.CellEditorInitializeEventArgs) Handles cboCellEditor.InitializeControl
Stop
End Sub
Private Sub cboCellEditor_GetControlValue(sender As Object, e As Infralution.Controls.VirtualTree.CellEditorGetValueEventArgs) Handles cboCellEditor.GetControlValue
Stop
End Sub
Private Sub cboCellEditor_SetControlValue(sender As Object, e As Infralution.Controls.VirtualTree.CellEditorSetValueEventArgs) Handles cboCellEditor.SetControlValue
Stop
End Sub
cboCellEditor_InitializeControl is not firing. Thanks. _________________ Medical billing & records developer. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jul 09, 2012 12:00 pm Post subject: |
|
|
I've just verified that these events are firing by adding event handlers to the CellEditors in the Data Set Browser sample project and setting a debug break point (which was hit). I'm not sure why you aren't seeing that behaviour. It maybe related to how you are creating the CellEditors - are you doing this programatically or using the designer (via Edit Virtual Tree). If you can replicate you problem in a simple test project (or by modifying one of the sample projects) and email support@infralution.com a zipped copy we could provide more assistance/
Another (possibly better approach) if you want to have a custom drawn combo box would be to derive a new class from ComboBox and override the OnItemDraw method. Then you can just use your derived combo box in Virtual Tree as an editor without having to worry about using the InitializeControl event. _________________ Infralution Support |
|
Back to top |
|
|
medbiller
Joined: 20 Dec 2007 Posts: 39 Location: Arroyo, PR
|
Posted: Mon Jul 09, 2012 1:25 pm Post subject: |
|
|
I checked the DatabaseBrowser example & instead of using a VS2010 ComboBox I changed the editor to a UniversalCellEditor to no avail. However tese two programs are very different. I use Sql, GetCellData event and the other doen't. I can't even see where you are loading the comobobox for the cars model, etc. I wish I could call you & share my screen with you. I use LogMeInRescue. My project is databound to a large SQL 2010 database. It would take a while just to do the setup. _________________ Medical billing & records developer. |
|
Back to top |
|
|
medbiller
Joined: 20 Dec 2007 Posts: 39 Location: Arroyo, PR
|
Posted: Mon Jul 09, 2012 8:58 pm Post subject: |
|
|
Never mind. cboCellEditor_InitializeControl(...) will not fire if GetCellData(...) event is used to populate the editor.
Once populated a cell via _InitializeControl(...) , how can I re initalize that same cell with a diferent set of values depending on some condition changing on the Form? _________________ Medical billing & records developer. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jul 10, 2012 12:13 am Post subject: |
|
|
Quote: | Never mind. cboCellEditor_InitializeControl(...) will not fire if GetCellData(...) event is used to populate the editor. |
The InitializeControlEvent should still fire. I just checked this by adding a ComboBox as an editor to the Programmatic Binding sample project. I added the CellEditor using the Virtual Tree Editor - but then assigned the Editor to the cell in the GetCellData event ie:
Code: | private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
Part part = e.Row.Item as Part;
if (e.Column == this.colMain)
{
e.CellData.Value = part.Name;
e.CellData.Editor = comboBoxEditor;
}
} |
The InitializeControl event for the editor was fired the first time that the editor was actually used as expected. But I think that deriving a new control from ComboBox is probably a neater solution for what you want to do anyway (rather than using the InitializeControl event to attach a handler).
Quote: | Once populated a cell via _InitializeControl(...) , how can I re initalize that same cell with a diferent set of values depending on some condition changing on the Form? |
I'm not really sure what you mean by this? _________________ Infralution Support |
|
Back to top |
|
|
medbiller
Joined: 20 Dec 2007 Posts: 39 Location: Arroyo, PR
|
Posted: Tue Jul 10, 2012 12:34 am Post subject: |
|
|
When a particular cell in vTree was initialized with a ComboBox using cboCellEditor_InitializeControl(...) , then when you open the cell to see the DropDown you see the values. Since cboCellEditor_InitializeControl(...) fires only once, everytime I go into the cell I see the same values. I would like to set focus on another control outside vTree, change the DataSet that was used at the beginning so as to display a diferent set of values in the DropDown of the same cell when clicking back to it. _________________ Medical billing & records developer. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jul 10, 2012 12:56 am Post subject: |
|
|
If you want to change the combo box drop down each time then you probably need to handle the CellEditor.SetControlValue control eg
Code: | private void comboBoxEditor_SetControlValue(object sender, CellEditorSetValueEventArgs e)
{
// set the combo box data source or items
comboBox.Items.Clear();
comboBox.Items.Add(e.Value as string);
// set the combo value
//
ComboBox comboBox = (ComboBox)e.Control;
comboBox.Text = e.Value as string;
} |
_________________ Infralution Support |
|
Back to top |
|
|
|