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 

Context menu item to open file. Cell has reference to file

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



Joined: 12 Apr 2010
Posts: 7

PostPosted: Sun Apr 18, 2010 6:08 pm    Post subject: Context menu item to open file. Cell has reference to file Reply with quote

Dear Support,

In my treeview, there is a column named "Item" (colMain).
This column is used by several nodes (DataRow(x), DataRow(y) etc., from a xml-file)

In two of them there are references to a file path.
I'd like to add a context menu item to open the file (OpenFileDialog ) from one of them (the other isn't a valid path)

( selected cel-value matches data binding-DataRow(x) ???? )

Is this possible. (VS2008 - C#)

Thanks a lot,

Robertico
_________________
There are only 10 types of people in the world: Those who understand binary, and those who don't
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sun Apr 18, 2010 11:11 pm    Post subject: Reply with quote

You need to handle the GetContextMenuStrip event. Because the event arguments don't include the column which was clicked on you will need to determine this. The code below does this. It also gets file path from the cell data and stores it in the context menu strip tag - so that you can extract and use it when displaying the file dialog in the context menu click handler.

Code:
private void _virtualTree_GetContextMenuStrip(object sender, GetContextMenuStripEventArgs e)
{
    Point pt =  _virtualTree.PointToClient(MousePosition);
    CellWidget widget = _virtualTree.GetWidget(pt.X, pt.Y) as CellWidget;
    if (widget != null)
    {
        if (widget.Column == colFile)
        {
            string path = widget.CellData.Value as string;
            _contextMenu.Tag = path;
            e.ContextMenuStrip = _contextMenu;
        }
    }
}

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Robertico



Joined: 12 Apr 2010
Posts: 7

PostPosted: Mon Apr 19, 2010 6:47 am    Post subject: Reply with quote

This works for all the cells in the column.

But, this column is used by several nodes (DataRow(x), DataRow(y) etc., from a xml-file). In two of them there are references to a file path.
I'd like to add a context menu item to open the file from one of them (the other isn't a valid path).
So, if i select a cell in this column, i have to find out if it's the correct cell (with the valid path).

I thought that I had to verify the origin (Databinding)
I hope I'm able to clear a bit. (English is not my natural language).

Regards,

Robertco
_________________
There are only 10 types of people in the world: Those who understand binary, and those who don't
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Apr 19, 2010 7:25 am    Post subject: Reply with quote

You can find out the DataRow that the Virtual Tree row is bound from the event args eg:

Code:
DataRow dataRow = e.Row.Item as DataRow;

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Robertico



Joined: 12 Apr 2010
Posts: 7

PostPosted: Tue Apr 20, 2010 1:41 pm    Post subject: Reply with quote

Thank you. Fixed.

Great support !

Robertico
_________________
There are only 10 types of people in the world: Those who understand binary, and those who don't
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