<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Guillermo G. Blog : Windows Forms</title><link>http://weblogs.asp.net/guillermo/archive/tags/Windows+Forms/default.aspx</link><description>Tags: Windows Forms</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Tip: System.Data.Entity and ClickOnce Deployment Issue</title><link>http://weblogs.asp.net/guillermo/archive/2008/08/20/tip-system-data-entity-and-clickonce-deployment-issue.aspx</link><pubDate>Wed, 20 Aug 2008 19:59:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6543682</guid><dc:creator>gugonzar</dc:creator><author>gugonzar</author><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/guillermo/rsscomments.aspx?PostID=6543682</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/guillermo/commentapi.aspx?PostID=6543682</wfw:comment><comments>http://weblogs.asp.net/guillermo/archive/2008/08/20/tip-system-data-entity-and-clickonce-deployment-issue.aspx#comments</comments><description>&lt;p align="justify"&gt;I was developing a Windows forms application in .net framework 3.5, and I needed to include &lt;a href="http://msdn.microsoft.com/en-us/library/t71a733d(VS.80).aspx" target="_blank"&gt;ClickOnce Deployment&lt;/a&gt; in my solution project. Recently I downloaded and installed the last Service Pack (SP1) for Microsoft Visual Studio 2008 and .net framework 3.5, so far, everything was normal. The only application setup prerequisite was .net framework 3.5.&lt;/p&gt;  &lt;p align="justify"&gt;I published my application in a web server normally, and when I click the Install button to start the install process, I received the next error message from the ClickOnce Installer:&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://weblogs.asp.net/blogs/guillermo/WindowsLiveWriter/System.Data.EntityandClickOnceIssue_C844/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="97" alt="ClickOnce Message" src="http://weblogs.asp.net/blogs/guillermo/WindowsLiveWriter/System.Data.EntityandClickOnceIssue_C844/image_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p align="justify"&gt;The funny thing is that I didn't have any reference to System.Data.Entity in my solution, so? what's wrong? Why was ClickOnce requesting this assembly? &lt;/p&gt;  &lt;p align="justify"&gt;Well, after a quick search in Google, I found and read this &lt;a href="http://blogs.blackmarble.co.uk/blogs/msteeples/archive/2008/08/12/your-clickonce-clients-complain-of-a-missing-system-data-entity-reference-in-the-gac.aspx" target="_blank"&gt;Post&lt;/a&gt; from Mat Steeples, and I understood why ClickOnce was referencing System.Data.Entity assembly, simple!, I included a new feature (Create a Desktop Icon) and that functionality requires the mentioned assembly.&lt;/p&gt;  &lt;p align="justify"&gt;Thanks to &lt;a href="http://blogs.blackmarble.co.uk/members/Mat-Steeples.aspx"&gt;Mat Steeples&lt;/a&gt; for sharing it.    &lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6543682" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/guillermo/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/guillermo/archive/tags/Windows+Forms/default.aspx">Windows Forms</category><category domain="http://weblogs.asp.net/guillermo/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://weblogs.asp.net/guillermo/archive/tags/Deployment/default.aspx">Deployment</category></item><item><title>Tip: DataSet.HasChanges and Windows Form Close Button Strange Behavior</title><link>http://weblogs.asp.net/guillermo/archive/2008/01/22/tip-dataset-haschanges-and-windows-form-close-button-estrange-behavior.aspx</link><pubDate>Tue, 22 Jan 2008 14:12:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5635180</guid><dc:creator>gugonzar</dc:creator><author>gugonzar</author><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/guillermo/rsscomments.aspx?PostID=5635180</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/guillermo/commentapi.aspx?PostID=5635180</wfw:comment><comments>http://weblogs.asp.net/guillermo/archive/2008/01/22/tip-dataset-haschanges-and-windows-form-close-button-estrange-behavior.aspx#comments</comments><description>&lt;P align=justify&gt;I had to write a simple Windows Forms application that haves a form. This form contains a &lt;EM&gt;DataGridView&lt;/EM&gt; control that is binded with a &lt;EM&gt;DataSet&lt;/EM&gt;; this &lt;EM&gt;DataSet&lt;/EM&gt; is filled with data from an XML file. This Windows Forms contains two buttons: "Accept Changes" and "Cancel Changes". &lt;/P&gt;
&lt;P align=justify&gt;The "Accept Changes" and "Cancel Changes" buttons works greatly, the first one writes the content of the &lt;EM&gt;DataGridView&lt;/EM&gt; control in a &lt;EM&gt;XML DataSet&lt;/EM&gt;, and the second one simply cancel the data insertion, delete or modifying operation and shows a message indicating to the user if wants to discard or save all changes made to the &lt;EM&gt;DataGridView&lt;/EM&gt; control. Both the "&lt;EM&gt;Cancel Changes" &lt;/EM&gt;and the standard window close button executes the following method:&lt;/P&gt;
&lt;DIV class=csharpcode&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;1:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; CloseWindow()&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;2: &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;3:&lt;/SPAN&gt;  dvProviders = dgvProviders.DataSource &lt;SPAN class=kwrd&gt;as&lt;/SPAN&gt; DataView;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;4:  &lt;/SPAN&gt;DataSet dsProviders = dvProviders.Table.DataSet;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;5:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;6:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (dsProviders.HasChanges())&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;7:  &lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;8:  &lt;/SPAN&gt; DialogResult saveChanges = MessageBox.Show(&lt;SPAN class=str&gt;"¿Save Changes?"&lt;/SPAN&gt;,&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;9:  &lt;/SPAN&gt; &lt;SPAN class=str&gt;"Save"&lt;/SPAN&gt;, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;10:  &lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;11:  &lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; saveChanges == DialogResult.Yes)&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;12:  &lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;13:  &lt;/SPAN&gt;  &lt;SPAN class=rem&gt;//Save the changes from the DataSet to an XML file&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;14:  &lt;/SPAN&gt;  &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.SaveChanges();&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;15:  &lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN class=lnum&gt;16:  &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;17: &lt;/SPAN&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;
&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;But &lt;U&gt;what&lt;/U&gt; happens if the user close the window using the standard window's close button and the &lt;EM&gt;DataGridView's&lt;/EM&gt;&amp;nbsp;&lt;EM&gt;DataSource&lt;/EM&gt; (a &lt;EM&gt;DataSet&lt;/EM&gt;) have pending changes? &lt;BR&gt;It is expected that the button execute the &lt;EM&gt;CloseWindow&lt;/EM&gt; method and detect if the &lt;EM&gt;DataSet&lt;/EM&gt; has changes, but in a rare way when the code ask for the result of the &lt;EM&gt;DataSet's&lt;/EM&gt; &lt;EM&gt;HasChanges&lt;/EM&gt; method, it returns a false value and all the changes made in the &lt;EM&gt;DataGridView&lt;/EM&gt; control are lost when the window close. &lt;/P&gt;
&lt;P align=justify&gt;Well, Fortunately with the help of a coworker that told me that it was a "Bug" or better called "Windows Form's rare behavior". He told me that I need to move the focus of the &lt;EM&gt;DataGridView&lt;/EM&gt; control to other control in the form (for example the Accept Changes button) before asking for the &lt;EM&gt;DataSet's HasChanges&lt;/EM&gt; method, this way the &lt;EM&gt;DataGridView&lt;/EM&gt; control apply the changes to the &lt;EM&gt;DataSet&lt;/EM&gt; and the &lt;EM&gt;HasChanges&lt;/EM&gt; return true (if any change is made to the &lt;EM&gt;DataGridView&lt;/EM&gt; control) and the method's execution continues normally.&lt;/P&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;  5:     &lt;SPAN class=rem&gt;// Set the focus to other control&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;  6:      btnAcceptChanges.Focus();&lt;/PRE&gt;&lt;/DIV&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;  7:      &lt;/PRE&gt;&lt;/DIV&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt;  8:      &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (dsProviders.HasChanges())&lt;/PRE&gt;&lt;/DIV&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;  9:      {&lt;/PRE&gt;&lt;/DIV&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE&gt; 10:      ...&lt;/PRE&gt;&lt;/DIV&gt;
&lt;STYLE type=text/css&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;Thanks to &lt;A href="http://apuyana.no-ip.com/apuyana/" target=_blank mce_href="http://apuyana.no-ip.com/apuyana/"&gt;Alberto Puyana&lt;/A&gt; for help me find the answer to this windows close button strange behavior. &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5635180" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/guillermo/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/guillermo/archive/tags/Tip/default.aspx">Tip</category><category domain="http://weblogs.asp.net/guillermo/archive/tags/Windows+Forms/default.aspx">Windows Forms</category><category domain="http://weblogs.asp.net/guillermo/archive/tags/C_2300_/default.aspx">C#</category></item></channel></rss>