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 

File browse button in column

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



Joined: 20 Nov 2007
Posts: 23
Location: Netherlands

PostPosted: Tue Nov 20, 2007 9:08 am    Post subject: File browse button in column Reply with quote

Dear Support,

in my treeview, there is a column named "filename". Is it possible to add a browse button in each cell of this column? When user clicks this button, an OpenFileDialog or something similar should open.

Thanks a lot,

Anja
Back to top
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Nov 20, 2007 10:55 pm    Post subject: Reply with quote

If the browse button will be the only thing in the control then this is relatively simple. Create a CellEditor using a Button control as the editor control. Set this to be the CellEditor for the column.

Because the editor control (in this case a Button) is just a template for the editor controls actually created at runtime you can't add event handlers to it (actually you can - but they won't get called). To attach event handlers to the runtime controls you need to handle the CellEditor.InitializeControl event and add the event handlers there eg

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


If you want to display both text (say the filename) and a button in the same column then you could create a custom user control which combines a label (to display the text) and a button and use this as an Editor Control. However perhaps a better way to achieve this would be to define a custom TypeEditor for editing filenames eg

Code:
public class FileNameEditor : UITypeEditor
{

    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        if (ofd.ShowDialog() == DialogResult.OK)
            return ofd.FileName;
        return value;
    }
}


You then associate this TypeEditor with property on your object that returns the FileName using the Editor attribute:

Code:
[Editor(typeof(FileNameEditor), typeof(UITypeEditor))]
public string FileName
{
    get { return _filename; }
    set { _filename = value; }
}


Now if you use an Infralution UniversalEditBox as the Editor control it will automatically use your custom TypeEditor to edit the cell values. It provides a button to the right which when clicked will now display the FileDialog. I would probably set the the CellEditor.DisplayMode to OnEdit to avoid having the edit boxes displayed when you don't need them.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
AB



Joined: 20 Nov 2007
Posts: 23
Location: Netherlands

PostPosted: Wed Nov 21, 2007 9:34 am    Post subject: Reply with quote

Thanks a lot for your answer, it works great, very good support!

Anja
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