<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; menuSelect</title>
	<atom:link href="http://blog.flexexamples.com/tag/menuselect/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using a custom context menu with the Flex DataGrid control</title>
		<link>http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/</link>
		<comments>http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 05:19:53 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ContextMenu]]></category>
		<category><![CDATA[ContextMenuItem]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[menuItemSelect]]></category>
		<category><![CDATA[menuSelect]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/</guid>
		<description><![CDATA[<p>I saw this question come up on a list today and thought this was pretty handy. Plus, I think it is the first time I&#8217;ve had a chance to play with the ContextMenu and ContextMenuItem classes in Flex in quite a while.</p> <p>The following example pops up a custom context menu when the user right-clicks [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this question come up on a list today and thought this was pretty handy. Plus, I think it is the first time I&#8217;ve had a chance to play with the ContextMenu and ContextMenuItem classes in Flex in quite a while.</p>
<p>The following example pops up a custom context menu when the user right-clicks on an item in an data grid. After selecting the custom item (&#8220;View item&#8230;&#8221;) from the context menu an Alert control is displayed showing the selected item&#8217;s properties.</p>
<p>Full code after the jump.</p>
<p><span id="more-105"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/DataGrid_contextMenu_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Alert;

            [Bindable]
            private var cm:ContextMenu;

            private var alert:Alert;

            private function init():void {
                var cmi:ContextMenuItem = new ContextMenuItem("View item...", true);
                cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect);

                cm = new ContextMenu();
                cm.hideBuiltInItems();
                cm.customItems = [cmi];
                cm.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenu_menuSelect);
            }

            private function contextMenu_menuSelect(evt:ContextMenuEvent):void {
                dataGrid.selectedIndex = lastRollOverIndex;
            }

            private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void {
                var obj:Object = dataGrid.selectedItem;
                alert = Alert.show("Property A: " + obj.@propertyA + "\\n" + "Property B: " + obj.@propertyB, obj.@label, Alert.OK);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XML id="itemsXML"&gt;
        &lt;items&gt;
            &lt;item label="Item 1" data="i001" propertyA="Item 1.A" propertyB="Item 1.B" /&gt;
            &lt;item label="Item 2" data="i002" propertyA="Item 2.A" propertyB="Item 2.B" /&gt;
            &lt;item label="Item 3" data="i003" propertyA="Item 3.A" propertyB="Item 3.B" /&gt;
            &lt;item label="Item 4" data="i004" propertyA="Item 4.A" propertyB="Item 4.B" /&gt;
            &lt;item label="Item 5" data="i005" propertyA="Item 5.A" propertyB="Item 5.B" /&gt;
            &lt;item label="Item 6" data="i006" propertyA="Item 6.A" propertyB="Item 6.B" /&gt;
            &lt;item label="Item 7" data="i007" propertyA="Item 7.A" propertyB="Item 7.B" /&gt;
            &lt;item label="Item 8" data="i008" propertyA="Item 8.A" propertyB="Item 8.B" /&gt;
        &lt;/items&gt;
    &lt;/mx:XML&gt;

    &lt;mx:Number id="lastRollOverIndex" /&gt;

    &lt;mx:DataGrid id="dataGrid"
            width="400"
            dataProvider="{itemsXML.item}"
             contextMenu="{cm}"
             itemRollOver="lastRollOverIndex = event.rowIndex"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn id="labelCol"
                    dataField="@label"
                    headerText="Label:" /&gt;

            &lt;mx:DataGridColumn id="propACol"
                    dataField="@propertyA"
                    headerText="Property A:" /&gt;

            &lt;mx:DataGridColumn id="propBCol"
                    dataField="@propertyB"
                    headerText="Property B:" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

    &lt;mx:Label text="{dataGrid.selectedItem.@label}" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/DataGrid_contextMenu_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/DataGrid_contextMenu_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using a custom context menu with the Flex DataGrid control on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/',contentID: 'post-105',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'menuItemSelect,menuSelect',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
	</channel>
</rss>

