View previous topic :: View next topic |
Author |
Message |
Robertico
Joined: 12 Apr 2010 Posts: 7
|
Posted: Sun Apr 18, 2010 6:08 pm Post subject: Context menu item to open file. Cell has reference to file |
|
|
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 |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Apr 18, 2010 11:11 pm Post subject: |
|
|
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 |
|
|
Robertico
Joined: 12 Apr 2010 Posts: 7
|
Posted: Mon Apr 19, 2010 6:47 am Post subject: |
|
|
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 |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Apr 19, 2010 7:25 am Post subject: |
|
|
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 |
|
|
Robertico
Joined: 12 Apr 2010 Posts: 7
|
Posted: Tue Apr 20, 2010 1:41 pm Post subject: |
|
|
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 |
|
|
|