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 

Button as editor

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



Joined: 06 Jun 2006
Posts: 12

PostPosted: Wed Jun 07, 2006 1:27 pm    Post subject: Button as editor Reply with quote

Hi. I have a button as an editor and i want to fire Clik event . How can i do that ??
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Jun 08, 2006 9:39 am    Post subject: Reply with quote

Because the Editor control (in this case a button) is just a template for the actual controls that are created and used by Virtual Tree you can't just add an event handler to the template control. Instead you must handle the Editor InitializeControl event which is called each time Virtual Tree creates a new control using the editor.

To do this select the editor in the Virtual Tree editor and then select the event tab in the property window. Double click on the InitializeControl event entry to create a new event handler for this. When you close the Virtual Tree editor the code window will automatically open at this point. Then programatically add your click event handler as shown below:

Code:
private void buttonEditor_InitializeControl(object sender, CellEditorInitializeEventArgs e)
{
    if (e.NewControl)
    {
        e.Control.Click +=new EventHandler(OnButtonClick);
    }
}

private void OnButtonClick(object sender, EventArgs e)
{
    Button button = sender as Button;
    Debug.WriteLine(button.Tag);
}


The only other issue is how do you know which button was clicked? Probably the best way to do this is to set the ValueProperty of the CellEditor (in the Virtual Tree designer) to the Tag property of the button. This means that Virtual Tree will automatically set the Tag property of the button to whatever data is in the cell.

If you are using object binding you can simply set the CellBinding.Field property to nothing and Virtual Tree will set the cell value (and hence the Tag property of the button) to the actual item for that row.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Muralidhar
Guest





PostPosted: Tue Aug 22, 2006 2:40 pm    Post subject: Handling checked box event Reply with quote

Following the above method ...I can capture the event for a checkBoxChecked . I am using check box on a prefix column.

Further, I want to check the checkboxes on the child items if the parent is checked and vice-versa ...how can I do that ?? ... the parameters passed in do not have enuf data.
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Aug 22, 2006 10:51 pm    Post subject: Reply with quote

For a checkbox you shouldn't have to use the method above - since you can bind your data to the CheckBox Checked property. This is the default for checkboxes. When the checkbox fires the CheckedChanged event then VirtualTree will change the bound data value.

To change the check state of children when the parent state is changed simply handle the SetCellValue event (or override the SetValueForCell method) eg

Code:
private void _virtualTree_SetCellValue(object sender, SetCellValueEventArgs e)
{
     // use the row binding to set the value by default
     //
     RowBinding binding = _virtualTree.GetBindingForRow(e.Row);
     binding.SetCellValue(e.Row, e.Column, e.OldValue, e.NewValue);

     // if the checked value is changed then set the child check state accordingly
     //
     if (e.Column == this.myCheckColumn)
     {
            // get your data item from the row
            //
            MyItem item = e.Row.Item as MyItem;
           
            // now iterate over its children setting their check state

            // if your data items don't provide notifications of changes via
            // IListChanged event then you'll need to force the tree to update
            //
            _virtualTree.UpdateData();
     }
 }


If you are binding the CheckState to a property of your data items then another alternative is to have your data model actually implement this. ie the set property for the parent items would iterate through the child objects and set the checked property.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
RGabo



Joined: 21 Sep 2005
Posts: 11

PostPosted: Fri Jan 05, 2007 5:34 am    Post subject: button as cell editor -> too slow Reply with quote

Hi Infralution,

I am a great admirer of your virtual tree and your support is just mind blowing! That's why I'm turning here for help.

I would like to have a button in each row in a given column with ShowAlways. I would like to be able to click this button and act upon the row in which the button is. You have described how this can be done, so it should be no problem.

My problem is that if I either have a PictureBox or a System.Windows.Forms.Button (tried your ThemedButton too), your virtual tree gets too slow and most of the cells don't get even drawn while items are added, but only the buttons one by one, half a second each. So its not really usable.

Is there anything I could check why things could go this slow?
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jan 05, 2007 8:57 am    Post subject: Reply with quote

My guess is that this may be related to a problem experienced by another customer (see http://www.infralution.com/phpBB2/viewtopic.php?t=540). This seemed to be hardware (display card) related - however on all hardware we have tested on we haven't experienced the issue. We even went to the extent of getting the exact same hardware as the customer - but were unable to replicate the problem.

Does the FileBrowser sample (with checkboxes) show the same issue.
What display card/driver are you using? It may be a driver issue - try getting the latest drivers for your display card.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
RGabo



Joined: 21 Sep 2005
Posts: 11

PostPosted: Fri Jan 05, 2007 9:09 am    Post subject: Reply with quote

Infralution wrote:
My guess is that this may be related to a problem experienced by another customer (see http://www.infralution.com/phpBB2/viewtopic.php?t=540). This seemed to be hardware (display card) related - however on all hardware we have tested on we haven't experienced the issue. We even went to the extent of getting the exact same hardware as the customer - but were unable to replicate the problem.

Does the FileBrowser sample (with checkboxes) show the same issue.
What display card/driver are you using? It may be a driver issue - try getting the latest drivers for your display card.


Thanks for the reply.

I saw that thread and I don't have any problems with the FileBrowser. Could it be that a 16x16 PNG is too heavy to clone that many times? I either have a PictureBox with a 16x16 PNG or a button with a similar image (16x16 too).

not sure what could be causing it, but I am sure it is not a video card issue.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jan 05, 2007 9:13 am    Post subject: Reply with quote

Do you have the problem if you use a button without the image? Maybe you could send us a sample project (support@infralution.com) and we will see if we can replicate your issue.

The image is actually stored in the resources as a BMP regardless of the original format. If the image is 16x16 I can't see this being an issue.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
RGabo



Joined: 21 Sep 2005
Posts: 11

PostPosted: Fri Jan 05, 2007 9:15 am    Post subject: Reply with quote

Infralution wrote:
Do you have the problem if you use a button without the image? Maybe you could send us a sample project (support@infralution.com) and we will see if we can replicate your issue.

The image is actually stored in the resources as a BMP regardless of the original format. If the image is 16x16 I can't see this being an issue.


yes, I have the issue without the images on the buttons.
I'll see what I can do regarding the sample project.

Thanks!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
RGabo



Joined: 21 Sep 2005
Posts: 11

PostPosted: Fri Jan 05, 2007 6:46 pm    Post subject: Reply with quote

This issue happens under the following circumstances:

The virtual tree is bound to a BindingSource and the object binding is through ITypedList. A BindingList<Foo> is bound to the BindingSource instance and it initially contains no items.

Items are added one-by-one by calling bindingList.Add(new Foo()) on the UI thread. This is where virtual tree takes a lot of time to add the item with the custom editor (may that be a checkbox or picturebox.. i'm using both).

If surrounded with SuspendDataUpdate/ResumeDataUpdate, adding items is no time and upon ResumeDataUpdate, the view instantly shows the checkboxes.

That makes me think there's a bug with how change notifications are handled.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
RGabo



Joined: 21 Sep 2005
Posts: 11

PostPosted: Fri Jan 05, 2007 6:46 pm    Post subject: Reply with quote

argh, I accidentally posted twice.

Last edited by RGabo on Fri Jan 05, 2007 6:50 pm; edited 1 time in total
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sat Jan 06, 2007 1:29 am    Post subject: Reply with quote

If you are adding a lot of items you definitely should use Suspend/ResumeDataUpdate. If you think there is still an issue email us a sample project.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
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