<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Tech Tip: Split Button Configuration</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : Tech Tip: Split Button Configuration</description>
  <pubDate>Fri, 12 Jun 2026 11:24:12 -700</pubDate>
  <lastBuildDate>Wed, 06 Jun 2007 14:53:38 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=54</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Tech Tip: Split Button Configuration : Level 200 DevForce Express July...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=54&amp;PID=125#125</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=21" rel="nofollow">IdeaBlade</a><br /><strong>Subject:</strong> 54<br /><strong>Posted:</strong> 06-Jun-2007 at 2:53pm<br /><br /><P =Questi&#111;n style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman" size=3><strong><EM>Level 200 <BR>DevForce Express</EM></strong></FONT></P><P =Questi&#111;n style="MARGIN: 0in 0in 0pt"><strong><EM><FONT face="Times New Roman" size=3>July 11, 2006</FONT></EM></strong></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt"><FONT face="Times New Roman" size=2>There’s a nifty “split button” control among the .NET 2.0 controls that combines the functions of a regular button and a drop down. Clicking the main button runs the current “Default” command. Clicking the drop down button reveals alternative variants on that command. The user can pick any one of the listed items to run instead. </FONT></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt"><FONT face="Times New Roman" size=2>We thought you might enjoy an example to supplement the somewhat obscure documentation from Microsoft.</FONT></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt"><FONT face="Times New Roman" size=2>The Funhouse employee page places a split button on a ToolStrip. The default action of the split button’s main button reverses all pending changes to all employees.</FONT></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt"><?:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shape id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:ulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:ulas><v:path o:c&#111;nnect="rect" gradientshapeok="t" o:extrusi&#111;nok="f"></v:path><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shape>&nbsp;</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt" align=center><FONT face="Times New Roman" size=2><img src="http://www.ideablade.com/Forum/uploads/20070606_175055_SNAG-0015.jpg" height="70" width="79" border="0" /></FONT></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"><FONT face="Times New Roman" size=2></FONT>&nbsp;</P><FONT face="Times New Roman" size=2><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">The drop down offers two flavors of undo: </P><UL style="MARGIN-TOP: 0in" =disc><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">“Undo All”, the default </LI><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">“Undo Current” which reverses changes to the current employee only </LI></UL><DIV></DIV><DIV></DIV><DIV>&nbsp;</DIV><P align=center><img src="http://www.ideablade.com/Forum/uploads/20070606_175201_SNAG-0016.jpg" height="86" width="183" border="0" /></P><DIV></DIV><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">We decided that an item selected from the drop down should become the new default item. The illustration shows the user picking “Undo Current”. After selection, this becomes the main button’s default</P><DIV></DIV><DIV></DIV><DIV></DIV><P align=center><img src="http://www.ideablade.com/Forum/uploads/20070606_175301_SNAG-0017.jpg" height="68" width="102" border="0" /></P><DIV></DIV><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt">The coding game plan is simple:</P><UL style="MARGIN-TOP: 0in" =disc><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">Add menu items to the SplitButton’s <SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'">DropDownItems</SPAN> collection </LI><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">Attach a click handler to each menu item; the handler performs the corresponding command </LI><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">Write a method <SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'">(SetUndoButtonDefaultItem)</SPAN> to (re)set the SplitButton’s default menu item and update its appearance </LI><LI =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in">Call that default set method once during configuration and in each of the menu item handlers </LI></UL><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; LINE-HEIGHT: 14.4pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><B><SPAN style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Arial">C#:</SPAN></B><SPAN style="FONT-SIZE: 12pt"><o:p></o:p></SPAN></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>private void ConfigureUndoSplitButton() {<BR>&nbsp;&nbsp;ToolStripItemCollection dropDownItems = <BR>&nbsp;&nbsp;&nbsp;&nbsp;Page.UndoSplitButton.DropDownItems;<BR>&nbsp;&nbsp;ToolStripItem item;<BR><BR>&nbsp;&nbsp;item = dropDownItems.Add("Undo All");<BR>&nbsp;&nbsp;item.Click += UndoAllHandler;<BR>&nbsp;&nbsp;SetUndoButtonDefaultItem(item);&nbsp; </strong></FONT><I><SPAN style="COLOR: #006666; FONT-FAMILY: Arial"><strong><FONT style=": #e6e6e6">// initial default.<BR><BR></FONT></strong></SPAN></I><strong><FONT style=": #e6e6e6"><FONT face="Courier New" color=#808080>&nbsp;&nbsp;item = dropDownItems.Add("Undo Current");<BR>&nbsp;&nbsp;item.Click += UndoCurrentHandler;<BR>}<BR><BR>private void SetUndoButtonDefaultItem(ToolStripItem item) {<BR>&nbsp;&nbsp;ToolStripSplitButton button = Page.UndoSplitButton;<BR>&nbsp;&nbsp;button.DefaultItem = item;<BR>&nbsp;&nbsp;button.Text = item.Text;<BR></FONT><I><SPAN style="COLOR: #006666; FONT-FAMILY: Arial">&nbsp;&nbsp;&nbsp;&nbsp;// ToDo: handle item images if decide to use them.</SPAN></I><BR></FONT></strong><strong><FONT style=": #e6e6e6" face="Courier New" color=#808080>}<BR><BR>private void UndoAllHandler(object sender, EventArgs e) {<BR>&nbsp;&nbsp;ToolStripItem item = (ToolStripItem)sender;<BR>&nbsp;&nbsp;SetUndoButtonDefaultItem(item);<BR>&nbsp;&nbsp;PerformUndo(item.Text, GetAllChangedEmployees());<BR>} </FONT></strong></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt; LINE-HEIGHT: 14.4pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN><BR><strong>VB.NET:</strong></SPAN><SPAN style="FONT-SIZE: 12pt"><o:p></o:p></SPAN></P><P =CodeSnippet style="MARGIN: 0in 0in 0pt 0.25in"><FONT style=": #e6e6e6" face="Courier New" color=#808080><strong>Private Sub ConfigureUndoSplitButton()<BR>&nbsp;&nbsp;Dim dropDownItems As ToolStripItemCollection = _<BR>&nbsp;&nbsp;&nbsp;&nbsp;Page.UndoSplitButton.DropDownItems<BR>&nbsp;&nbsp;Dim item As ToolStripItem<BR><BR>&nbsp;&nbsp;item = dropDownItems.Add("Undo All")<BR>&nbsp;&nbsp;AddHandler item.Click, AddressOf UndoAllHandler<BR>&nbsp;&nbsp;SetUndoButtonDefaultItem(item) &nbsp;&nbsp;</strong></FONT><I><SPAN style="COLOR: #006666; FONT-FAMILY: Arial"><strong><FONT style=": #e6e6e6">' initial default.<BR><BR></FONT></strong></SPAN></I><strong><FONT style=": #e6e6e6"><FONT face="Courier New" color=#808080>&nbsp;&nbsp;item = dropDownItems.Add("Undo Current")<BR>&nbsp;&nbsp;AddHandler item.Click, AddressOf UndoCurrentHandler<BR>End Sub<BR><BR>Private Sub SetUndoButtonDefaultItem(ByVal item As ToolStripItem)<BR>&nbsp;&nbsp;Dim button As ToolStripSplitButton = Page.UndoSplitButton<BR>&nbsp;&nbsp;button.DefaultItem = item<BR>&nbsp;&nbsp;button.Text = item.Text<BR></FONT><I><SPAN style="COLOR: #006666; FONT-FAMILY: Arial">&nbsp;&nbsp;&nbsp;&nbsp;' ToDo: handle item images if decide to use them.</SPAN></I><BR></FONT></strong><strong><FONT style=": #e6e6e6" face="Courier New" color=#808080>End Sub<BR><BR>Private Sub UndoAllHandler( _<BR>&nbsp;&nbsp;&nbsp;&nbsp;ByVal sender As Object, ByVal e As EventArgs)<BR>&nbsp;&nbsp;Dim item As ToolStripItem = CType(sender, ToolStripItem)<BR>&nbsp;&nbsp;SetUndoButtonDefaultItem(item)<BR>&nbsp;&nbsp;PerformUndo(item.Text, GetAllChangedEmployees())<BR>End Sub</FONT></strong></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt"><strong>Remember:</strong> Pressing a ToolStrip button does not complete a currently open data binding action. The user’s last data entry could be lost.</P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Helvetica">This does not matter for undo – we are going to discard pending changes anyway. But if this were a different button – a Save button, for example – we would have to close the uncompleted binding explicitly by calling </SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'">Page.Validate()</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Helvetica"> in each of the handlers.<o:p></o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 8pt 0in 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Helvetica">Check out our other Tech Tips for the full story on this issue and for other nifty clues to programming .NET applications.<o:p></o:p></SPAN></P><DIV></DIV><DIV></DIV><DIV></DIV><DIV></DIV><DIV></DIV><DIV></DIV><DIV></DIV></FONT>]]>
   </description>
   <pubDate>Wed, 06 Jun 2007 14:53:38 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=54&amp;PID=125#125</guid>
  </item> 
 </channel>
</rss>