<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Lautz of .NET - Code</title>
    <link>http://www.malachicomputer.com/blog/</link>
    <description />
    <language>en-us</language>
    <copyright>Malachi Computer Consultants</copyright>
    <lastBuildDate>Tue, 13 Jul 2010 19:56:56 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>jason@malachicomputer.com</managingEditor>
    <webMaster>jason@malachicomputer.com</webMaster>
    <item>
      <trackback:ping>http://www.malachicomputer.com/blog/Trackback.aspx?guid=521c7f93-210f-48ca-99a9-9269269fc785</trackback:ping>
      <pingback:server>http://www.malachicomputer.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.malachicomputer.com/blog/PermaLink,guid,521c7f93-210f-48ca-99a9-9269269fc785.aspx</pingback:target>
      <dc:creator>Jason Lautzenheiser</dc:creator>
      <wfw:comment>http://www.malachicomputer.com/blog/CommentView,guid,521c7f93-210f-48ca-99a9-9269269fc785.aspx</wfw:comment>
      <wfw:commentRss>http://www.malachicomputer.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=521c7f93-210f-48ca-99a9-9269269fc785</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I ran into a situation where I needed to know what control was gaining focus in the
Leave() event of another control.  The situation I was working with is as follows; 
I have a multi-line text box that when it gains focus I want a listview of potential
values to popup below it.  When the textbox loses focus, the listview should
be hidden.   The user should be able to click on the listview to select
items to input into the textbox.  The problem was when the user clicked on the
listview, the textbox lost focus and was hiding the listview.  
</p>
        <p>
 
</p>
        <p>
Enter the ActiveControl property on the form.  This handy property allows me
to check, in the Leave() event, what is the new active control with focus.  Thus
I can check to see if the textbox lost the focus to the listview control and if so,
skip the hiding of it.  
</p>
        <p>
 
</p>
        <p>
Here we have the textbox named txtComplaint, when it gets the focus we make listView
visible.
</p>
        <p>
 
</p>
        <pre class="code">
          <span style="color: blue">private void </span>txtComplaint_Enter(<span style="color: blue">object </span>sender,
System.<span style="color: #2b91af">EventArgs </span>e) { listView.Visible = <span style="color: blue">true</span>;
}</pre>
        <p>
 
</p>
        <p>
When the textbox loses focus we see if the ActiveControl is the listView, if not we
hide it.
</p>
        <pre class="code">
          <span style="color: blue">private void </span>txtComplaint_Leave(<span style="color: blue">object </span>sender,
System.<span style="color: #2b91af">EventArgs </span>e) { <span style="color: blue">if </span>(ActiveControl.Name
!= <span style="color: #a31515">"listView"</span>) treeComplaint.Visible = <span style="color: blue">false</span>;
}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <img width="0" height="0" src="http://www.malachicomputer.com/blog/aggbug.ashx?id=521c7f93-210f-48ca-99a9-9269269fc785" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.malachicomputer.com">Malachi Computer
Consultants</a>. 
</body>
      <title>ActiveControl to tell me the control gaining focus.</title>
      <guid isPermaLink="false">http://www.malachicomputer.com/blog/PermaLink,guid,521c7f93-210f-48ca-99a9-9269269fc785.aspx</guid>
      <link>http://www.malachicomputer.com/blog/ActiveControlToTellMeTheControlGainingFocus.aspx</link>
      <pubDate>Tue, 13 Jul 2010 19:56:56 GMT</pubDate>
      <description>&lt;p&gt;
I ran into a situation where I needed to know what control was gaining focus in the
Leave() event of another control.&amp;nbsp; The situation I was working with is as follows;&amp;nbsp;
I have a multi-line text box that when it gains focus I want a listview of potential
values to popup below it.&amp;nbsp; When the textbox loses focus, the listview should
be hidden.&amp;nbsp;&amp;nbsp; The user should be able to click on the listview to select
items to input into the textbox.&amp;nbsp; The problem was when the user clicked on the
listview, the textbox lost focus and was hiding the listview.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Enter the ActiveControl property on the form.&amp;nbsp; This handy property allows me
to check, in the Leave() event, what is the new active control with focus.&amp;nbsp; Thus
I can check to see if the textbox lost the focus to the listview control and if so,
skip the hiding of it.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Here we have the textbox named txtComplaint, when it gets the focus we make listView
visible.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;txtComplaint_Enter(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender,
System.&lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e) { listView.Visible = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
}&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
When the textbox loses focus we see if the ActiveControl is the listView, if not we
hide it.
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;txtComplaint_Leave(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender,
System.&lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e) { &lt;span style="color: blue"&gt;if &lt;/span&gt;(ActiveControl.Name
!= &lt;span style="color: #a31515"&gt;"listView"&lt;/span&gt;) treeComplaint.Visible = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img width="0" height="0" src="http://www.malachicomputer.com/blog/aggbug.ashx?id=521c7f93-210f-48ca-99a9-9269269fc785" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.malachicomputer.com"&gt;Malachi Computer
Consultants&lt;/a&gt;. </description>
      <comments>http://www.malachicomputer.com/blog/CommentView,guid,521c7f93-210f-48ca-99a9-9269269fc785.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
    </item>
  </channel>
</rss>