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 

Link label or button column

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





PostPosted: Mon Jul 04, 2005 4:15 am    Post subject: Link label or button column Reply with quote

Hi; great control; just purchased my license and plan to use it a lot.

In my data, one of the columns is "Field" and if a user clicks on the text in that column I'd like to be notified and be able to get a reference to the row that was clicked. If they click on other columns in a row I don't need to be notified.

To illustrate, I'd like to write something like this:

Code:

void CellClicked(object sender, CellClickedEventArgs e) {
    if(e.ColumnIndex == MyInterestingColumnIndex) {
        MyOperationOn(e.RowData);
    }
}


I tried doing this by setting up a LinkLabel Editor on the interesting column, but didn't like the way that was going. What's the right way to do this type of thing with the VirtualTree?

Thanks!

Jason
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Jul 04, 2005 12:13 pm    Post subject: Reply with quote

Adding an edit control is certainly one approach - if you want button type functionality (ie changing appearance as you click and hover etc) it is probably the best approach. For a button type control you would set the DisplayMode to Always so that you don't have to click first to get the control visible. The only painful part is that you can't directly add the Click event handler using the designer. This is because the control in the designer is a template (VirtualTree dynamically copies this to create as many instances as it actually needs for the current display). Unfortunately Microsoft make it impossible for us to copy the event handlers for the control. To add an event handlers you need to first add a handler to the CellEditor InitializeControl event - this is called each time a new editor control is created by VirtualTree - then you add the Click event handler programmatically.

Another approach is to add your CellWidget class and handle the click event yourself eg:

Code:

using Infralution.Controls;
using Infralution.Controls.VirtualTree;
public class MyCellWidget : CellWidget
{
        public MyCellWidget(RowWidget rowWidget, Column column)
            : base(rowWidget, column) {}

        protected override void OnMouseDown(MouseEventArgs e)
        {
            // do something
        }
}


To have VirtualTree use your new MyCellWidget you need to inherit from VirtualTree and override the CreateCellWidget method as follows:

Code:

protected override CellWidget CreateCellWidget(RowWidget rowWidget, Column column)
{
    if (column == MyColumn)  // only create it for a particular column
         return new MyCellWidget(rowWidget, column);
    else
         return base.CreateCellWidget(rowWidget, column);
}


Having said that - it would be nice if this were a little easier - and implementing an event that would allow something like your original code is already on our Feature Request list.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
JPettys



Joined: 04 Jul 2005
Posts: 1

PostPosted: Mon Jul 04, 2005 2:28 pm    Post subject: Reply with quote

Thanks for the thorough and quick response. What you say about adding to the Click event handler by the designer makes perfect sense; I think I'll try the InitializeControl route first.

Working with this control reminds me of Java Swing's JTable in its flexibility and extensibility; it's architecture "feels" right. All that said, I think VirtualTree's implementation seems to just work better.

Browsing the forums, I see quite a bit that overriding CreateCellWidget is pretty helpful. It might be easier for coders to hook into this with a CellWidgetCreator property on VirtualTree and an ICellWidgetCreator interface. By default the VirtualTree would work with the current implementation of widget creation, but if a coder sets VirtualTree.CellWidgetCreator to their own implementation of ICellWidgetCreator then the tree would use that for CellWidget creation.

Just a thought; maybe it would muddy up the design, but it would be more convenient than inheriting from VirtualTree, compiling, adding to VS.NET toolbox, and then dropping it it.

Thanks again for the excellent response!

Jason
_________________
www.pettysconsulting.com
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Jul 04, 2005 10:41 pm    Post subject: Reply with quote

Thanks for your feedback. Our original judgement was that creating new CellWidgets or RowWidgets was a specialized case - hence we thought the balance should be toward keeping the design simple. I guess the other factor is that if you have overridden the widget behaviour then it probably is better to inherit a new class from VirtualTree anyway so that you can use this behaviour in multiple places without reimplementing the same code all over the place.

If you have a local derived control class it is often easier just to bypass using the Toolbox mechanism altogether. Simply drop the original control on the form then modify the generated code (just two lines of code - or one if you haven't extended the public interface).

There are two other ways we could allow the user to specify the widgets to be created:

1. Allow user to specify the widget type and use reflection to create it. This would be OK if the widgets had a parameterless constructor - but places an implicit requirement on the derived classes if you use parameters. Also doesn't give you a way of selectively creating a particular widget based on other criteria.

2. Use a delegate function to create the widget. This has some appeal as it means the user doesn't have to create yet another class. They could just add a static creator method to their derived Widget class. This would probably be my preference. What do you think?
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Aug 12, 2005 4:08 am    Post subject: Reply with quote

Version 2.0.0 has now been released and includes a CellClicked event to make implementing this type of behaviour easier.
_________________
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