This problem was caused by a naming collision. I had created a form called
"Menu" which created a "Menu" class. Once I renamed my "Menu" class to
"Leslie" wrote:
> Hello,
>
> I am reviewing code that is based upon the example below. However, when I
> attempt to compile the code, I get a message that references the following
> line:
>
> selectedItem = menu.SelectedItem;
> The message says:
>
> 'Menu' does not contain a definition for 'SelectedItem'.
>
>
>
> I am using VS 2005 with the following Versioning information from Help->About:
> (Also, I have .NET Framework 3.0 SP1 installed on my system)
>
> Microsoft Visual Studio 2005
> Version 8.0.50727.762 (SP.050727-7600)
> Microsoft .NET Framework
> Version 2.0.50727 SP1
>
> Installed Edition: Enterprise
>
> Microsoft Visual Basic 2005 77642-113-3000004-41253
> Microsoft Visual Basic 2005
>
> Microsoft Visual C# 2005 77642-113-3000004-41253
> Microsoft Visual C# 2005
>
> Microsoft Visual C++ 2005 77642-113-3000004-41253
> Microsoft Visual C++ 2005
>
> Microsoft Visual Studio Tools for Office 77642-113-3000004-41253
> Microsoft Visual Studio Tools for the Microsoft Office System
>
> Microsoft Visual Web Developer 2005 77642-113-3000004-41253
> Microsoft Visual Web Developer 2005
>
> Microsoft Web Application Projects 2005 77642-113-3000004-41253
> Microsoft Web Application Projects 2005
> Version 8.0.50727.762
>
> Microsoft Web Deployment Projects 2005 77642-113-3000004-41253
> Microsoft Web Deployment Projects 2005
>
> Visual Studio 2005 Team Edition for Developers 77642-113-3000004-41253
> Microsoft Visual Studio 2005 Team Edition for Software Developers
>
> Crystal Reports AAC60-G0CSA4B-V7000AY
> Crystal Reports for Visual Studio 2005
>
>
> Dotfuscator Professional Edition
> Dotfuscator Professional Edition. Copyright (C) 2002-2005 PreEmptive
> Solutions, Inc.
>
> Microsoft Visual Studio 2005 Tools for the Microsoft Office System - ENU
> Service Pack 1 (KB926601)
> This service pack is for Microsoft Visual Studio 2005 Tools for the
> Microsoft Office System - ENU.
> If you later install a more recent service pack, this service pack will be
> uninstalled automatically.
> For more information, visit
http://support.microsoft.com/kb/926601 >
> Security Update for Microsoft Visual Studio 2005 Team Edition for Software
> Developers - ENU (KB937061)
> This Security Update is for Microsoft Visual Studio 2005 Team Edition for
> Software Developers - ENU.
> If you later install a more recent service pack, this Security Update will
> be uninstalled automatically.
> For more information, visit
http://support.microsoft.com/kb/937061 >
> SQL Server Analysis Services
> Microsoft SQL Server Analysis Services Designer
> Version 9.00.2047.00
>
> SQL Server Integration Services
> Microsoft SQL Server Integration Services Designer
> Version 9.00.2047.00
>
> SQL Server Reporting Services
> Microsoft SQL Server Reporting Services Designers
> Version 9.00.2047.00
>
> Visual Studio Tools for MySQL 1.0
> Data design and management tools for MySQL. Copyright © 2006 MySQL AB
>
>
> "Leslie" wrote:
>
> > Walter,
> >
> > Thanks for a good explanation as well as a good workaround.
> >
> > Leslie
> >
> > "Walter Wang [MSFT]" wrote:
> >
> > > Hi Leslie,
> > >
> > > The difference between the Menu and TreeView here is that TreeView
> > > implemented an additional interface IPostBackDataHandler and it will get
> > > the SelectedNode property before Page_Load. The menu's SelectedItem
> > > property is updated using MenuItem's Click event which is raised after
> > > Page_Load stage, therefore you're seeing the delay.
> > >
> > > Workaround:
> > >
> > > We can directly inspect the Request.Form to determine if the postback is
> > > caused by the Menu and get the selected MenuItem:
> > >
> > > protected void Page_Load(object sender, EventArgs e)
> > > {
> > > MenuItem mi = GetSelectedMenuItem(Menu1);
> > >
> > > if (mi != null)
> > > {
> > > Response.Write("Menu selected item = " + mi.Text);
> > > }
> > > else
> > > {
> > > Response.Write("Menu selected item = " + "No item selected");
> > > }
> > > Response.Write("<P/>");
> > > if (TreeView1.SelectedNode != null)
> > > {
> > > Response.Write("TreeView selected item = " +
> > > TreeView1.SelectedNode.Text);
> > > }
> > > else
> > > {
> > > Response.Write("TreeView selected item = " + "No item selected");
> > > }
> > >
> > > }
> > >
> > > MenuItem GetSelectedMenuItem(Menu menu)
> > > {
> > > MenuItem selectedItem = null;
> > > if (Request.Form["__EVENTTARGET"] == menu.ID)
> > > {
> > > string value = Request.Form["__EVENTARGUMENT"];
> > > if (!string.IsNullOrEmpty(value))
> > > {
> > > foreach (MenuItem mi in menu.Items)
> > > {
> > > if (mi.Value == value)
> > > {
> > > selectedItem = mi;
> > > break;
> > > }
> > > }
> > > }
> > > }
> > > else
> > > {
> > > selectedItem = menu.SelectedItem;
> > > }
> > > return selectedItem;
> > > }
> > >
> > >
> > > Sincerely,
> > > Walter Wang (wawang@online.microsoft.com, remove 'online.')
> > > Microsoft Online Community Support
> > >
> > > ==================================================
> > > Get notification to my posts through email? Please refer to
> > >
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif > > > ications. If you are using Outlook Express, please make sure you clear the
> > > check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
> > > promptly.
> > >
> > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> > > where an initial response from the community or a Microsoft Support
> > > Engineer within 1 business day is acceptable. Please note that each follow
> > > up response may take approximately 2 business days as the support
> > > professional working with you may need further investigation to reach the
> > > most efficient resolution. The offering is not appropriate for situations
> > > that require urgent, real-time or phone-based interactions or complex
> > > project analysis and dump analysis issues. Issues of this nature are best
> > > handled working with a dedicated Microsoft Support Engineer by contacting
> > > Microsoft Customer Support Services (CSS) at
> > >
http://msdn.microsoft.com/subscriptions/support/default.aspx.