<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><id>tag:battula32.blog.co.uk,2009-11-21:/</id><title>Technical Articles</title><link rel="self" href="http://battula32.blog.co.uk/feed/atom/posts/"/><link rel="alternate" type="text/html" href="http://battula32.blog.co.uk/"/><subtitle>I created this blog to post some of useful technical articles on Microsoft applications, mostly on C#, WCF and new technologies</subtitle><generator version="1.0">MokoFeed</generator><updated>2009-11-21T13:38:47+01:00</updated><entry><id>tag:battula32.blog.co.uk,2008-06-06:/2008/06/06/coding-horror-with-treeview-control-4280143/</id><title>Coding horror with Treeview control</title><link rel="alternate" type="text/html" href="http://battula32.blog.co.uk/2008/06/06/coding-horror-with-treeview-control-4280143/"/><author><name>battula32</name></author><published>2008-06-06T11:47:10+02:00</published><updated>2008-06-09T09:55:14+02:00</updated><content type="html">	&lt;p class="left"&gt;    In my application I have a tree view with different node and adjacent to it chart control is there. If I select any of the tree view node corresponding data will plot on chart control. On top of these controls grid is there, this will show the details of the selected node in tree view. All these controls are added in a panel (Called &lt;em&gt;main panel&lt;/em&gt;). I have one more panel (For editing purpose called &lt;em&gt;edit panel&lt;/em&gt;) behind this main panel. In this panel I am showing the same tree view and one more grid. Here we can edit the details of selected node.&lt;/p&gt;
	&lt;p class="left"&gt;    I am handling tree view selections almost like windows explorer. If we loose focus of tree view, I am just graying tree view node. I am just toggling main panel and edit panel if required to edit data of any node.&lt;/p&gt;
	&lt;p&gt;	I used C# 2.0&lt;/p&gt;
	&lt;p&gt;In this I faced lot of problems.&lt;/p&gt;
	&lt;p&gt;&lt;strong&gt;1&lt;/strong&gt;.	&lt;strong&gt;Tree view flicker&lt;/strong&gt;: When ever I select other node, tree view will flicker. Microsoft can’t able to provide direct solution for this. They suggested work around for this. The work around is use background thread. &lt;/p&gt;
	&lt;p class="left"&gt;    a.	The funniest thing here is in frame work 2.0 background worker thread has a bug. If you click continuously, frame work will though thread busy exception. Again Microsoft suggested to use Frame work 2.0 service pack1 (SP1).&lt;/p&gt;
	&lt;p class="left"&gt;    b.	My soft ware requirement is only frame work 2.0. Rests of the other applications are using only 2.0. (Because of back word compatibility issue and already sold software’s and also for some other reasons my bosses insisted not to use SP1.) , Again this came to staring position.&lt;/p&gt;
	&lt;p class="left"&gt;    c.	Then I use some work around trick like. If(Thread.IsBusy), with this tree view flickering problem is somehow solved.&lt;/p&gt;
	&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt;	&lt;strong&gt;Handling Focus in tree view&lt;/strong&gt;: User need to select any of node to plot data for that particular node. After selecting any node, the selected node data (Configuration) will be populated to a grid and plot will plot corresponding data.&lt;/p&gt;
	&lt;p class="left"&gt;     a.	If I want to edit any of the node configuration data, I have to go to &lt;em&gt;edit panel&lt;/em&gt;, which I am toggling panel using tool bar button. If I go to &lt;em&gt;edit panel&lt;/em&gt;, I am showing same tree view in that panel also (This tree view I am handling as user control). If I loose focus from tree view I am graying the color of selected node like windows explorer. &lt;/p&gt;
	&lt;p class="left"&gt;    b.	In this panel I selected some other node to edit the configuration of that node. Since I am using the same control, if I change the selection of tree view in &lt;em&gt;edit panel&lt;/em&gt;, this will reflect in &lt;em&gt;main panel &lt;/em&gt;also. Here I am maintaing some interlocks not lo load the data in plot curve and grid if I am working in &lt;em&gt;edit panel&lt;/em&gt;. But I can’t control that for tree view, because I have only one tree view. Here I edited some nodes I traversed to &lt;em&gt;Main panel&lt;/em&gt;.&lt;/p&gt;
	&lt;p class="left"&gt;    c.	While coming from &lt;em&gt;main panel&lt;/em&gt; to &lt;em&gt;edit panel &lt;/em&gt;, I am holding selected node name in &lt;em&gt;main panel&lt;/em&gt;,  With that name I am again setting the focus of tree view.&lt;/p&gt;
	&lt;p class="left"&gt;    d.	You may ask, why I am handling focus using node name instead of node number or node index. Because in &lt;em&gt;edit panel&lt;/em&gt; we have an option to move up and move down node positions. If I move node, then node index will change.&lt;/p&gt;
	&lt;p class="left"&gt;    e.	In &lt;em&gt;Main panel&lt;/em&gt;( Plot panel) always grid focus or grid selected item back color should be like highlight, To make that my co project member set the focus to this plot grid and that too he set focus to the grid in timer. At that time I was doing some other work and I lost track of that focus problems. After few days I realized that tree view focus is not there. Also I can’t able to edit the configuration of selected node from &lt;em&gt;edit panel&lt;/em&gt;. Because edit panel grid can’t able to hold focus.&lt;/p&gt;
	&lt;p class="left"&gt;    f.	After few hard hours and I realized that he set focus to &lt;em&gt;main panel &lt;/em&gt;grid in timer, because of that tree view and edit grid are not holding focuses, I changed that coding to back ground color change properties.&lt;/p&gt;
	&lt;p&gt;&lt;strong&gt;&lt;br&gt;
3.&lt;/strong&gt;	&lt;strong&gt;Tree view focus problems with panel visibility&lt;/strong&gt;: While coming to &lt;em&gt;main panel&lt;/em&gt; (plot panel) from &lt;em&gt;edit panel&lt;/em&gt;, My application loading like patches, grid is updating first, then tree view and then chart. To minimize those patch refreshes, I hide &lt;em&gt;main panel &lt;/em&gt;first after getting data to grid tree view and chart, I shown panel. With this also again I lost tree view focus.&lt;/p&gt;
&lt;p&gt; &lt;small&gt; &lt;a href="http://battula32.blog.co.uk/2008/06/06/coding-horror-with-treeview-control-4280143/#comments"&gt;Comments&lt;/a&gt; &lt;/small&gt; &lt;/p&gt;</content></entry><entry><id>tag:battula32.blog.co.uk,2007-08-21:/2007/08/21/copy_to_clipboard_functionality~2842811/</id><title>Copy To ClipBoard Functionality</title><link rel="alternate" type="text/html" href="http://battula32.blog.co.uk/2007/08/21/copy_to_clipboard_functionality~2842811/"/><author><name>battula32</name></author><published>2007-08-21T07:18:59+02:00</published><updated>2007-08-21T07:18:59+02:00</updated><content type="html">	&lt;p&gt;Hi,&lt;/p&gt;
	&lt;p&gt;Hereby I am going to present copy to clipboard functionality using C#.&lt;br&gt;This is very simple coding.&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;string sCopytoClipboard = "The string which you want to copy to clip board";&lt;br&gt;Clipboard.SetDataObject(sCopytoClipboard , true);&lt;br&gt;IDataObject iData = Clipboard.GetDataObject();&lt;br&gt;IDataObject data = Clipboard.GetDataObject();&lt;br&gt;if (data.GetDataPresent(typeof(string))) &lt;em&gt; If Clipboard has data then this will go into the loop&lt;br&gt;{&lt;br&gt;    string strData = (string)data.GetData(typeof(string)); &lt;/em&gt; StrData will be the copied data into the clipboard&lt;br&gt;}&lt;br&gt;&lt;/blockquote&gt;
 This part of code you have to call inside the event which you are trying to copy into clipboard like "Ctrl+C" or "Ctrl+X"&lt;/p&gt;
	&lt;p&gt;Regards&lt;br&gt;Ravi.Battula
&lt;/p&gt;
&lt;p&gt; &lt;small&gt; &lt;a href="http://battula32.blog.co.uk/2007/08/21/copy_to_clipboard_functionality~2842811/#comments"&gt;Comments&lt;/a&gt; &lt;/small&gt; &lt;/p&gt;</content></entry><entry><id>tag:battula32.blog.co.uk,2007-08-14:/2007/08/14/notepad_search_functionality~2806639/</id><title>Notepad search functionality</title><link rel="alternate" type="text/html" href="http://battula32.blog.co.uk/2007/08/14/notepad_search_functionality~2806639/"/><author><name>battula32</name></author><published>2007-08-14T14:04:38+02:00</published><updated>2007-08-14T14:14:48+02:00</updated><content type="html">	&lt;p&gt;Few months back, I had a problem of coding Find functionality in C#. I should work like notepad Find dailog box.&lt;/p&gt;
	&lt;p&gt;I used SetForegroundWindow(...), Actually this is not dialogbox, also this is not seperate window. Perhaps this is called from main window as &lt;em&gt;objSubForm.Show(this).&lt;br&gt;&lt;/em&gt;&lt;br&gt;the Idea I got from&lt;br&gt;&lt;a href="http://www.codeguru.com/forum/showthread.php?t=417099&amp;highlight=Find+Functionality+Notepad"&gt;&lt;a href="http://www.codeguru.com/forum/showthread.php?t=417099&amp;highlight=Find+Functionality+Notepad"&gt;http://www.codeguru.com/forum/showthread.php?t=417099&amp;highlight=Find+Functionality+Notepad&lt;/a&gt;&lt;/a&gt;&lt;br&gt;Hereby I am presenting sample code behind this.&lt;/p&gt;
	&lt;p&gt;      1.   Create windows application, add one more new  form to this project.&lt;br&gt;      2.   Declare one emplty object for second from.&lt;br&gt;                        Test.Form2 frm; // Test is namespace&lt;br&gt;      3.   In the constructor of main from create instance for second from like&lt;br&gt;                       ex. frm = new Test.Form2(this);  &lt;br&gt;      4.  In the second from you need to define on perameterised constructor and the parameter should be the object of main form &lt;br&gt;      5. The second form code will be like&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;using System.Runtime.InteropServices;&lt;/p&gt;
	&lt;p&gt;namespace Test&lt;br&gt;{&lt;br&gt;    public partial class Form2 : Form&lt;br&gt;    {&lt;br&gt;        Test.Form1 m_frm=null;&lt;br&gt;        [DllImport("user32.dll")] private static extern &lt;br&gt;            bool SetForegroundWindow(IntPtr hWnd);&lt;br&gt;        &lt;br&gt;        public Form2(Test.Form1 frm)&lt;br&gt;        {&lt;br&gt;            m_frm = frm;&lt;br&gt;            InitializeComponent();&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;       6. In main from Find event the code should be&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;frm.Show(this);&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt; &lt;small&gt; &lt;a href="http://battula32.blog.co.uk/2007/08/14/notepad_search_functionality~2806639/#comments"&gt;Comments&lt;/a&gt; &lt;/small&gt; &lt;/p&gt;</content></entry><entry><id>tag:battula32.blog.co.uk,2007-08-14:/2007/08/14/wcf_impersonation_behavior~2805953/</id><title>WCF Impersonation behavior</title><link rel="alternate" type="text/html" href="http://battula32.blog.co.uk/2007/08/14/wcf_impersonation_behavior~2805953/"/><author><name>battula32</name></author><published>2007-08-14T11:45:53+02:00</published><updated>2007-09-26T09:06:24+02:00</updated><content type="html">	&lt;p&gt;Today I found how to do settings for impersonation and configuration settings for impersonation.&lt;br&gt;This will be usuaful for the developers who are working on WCF.&lt;br&gt;Here I will expalin with the code&lt;/p&gt;
	&lt;p class="center"&gt;&lt;u&gt;&lt;strong&gt;Server Code&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;
	&lt;p&gt;In this I have two methods&lt;br&gt;One to create a text file, at the same time it will add some message ti tat text file&lt;br&gt;Other method is to read string from that text file.&lt;/p&gt;
	&lt;p&gt;In client Application I am calling these two methods.&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]&lt;br&gt;public void WriteToFile(string sText)&lt;em&gt; This will create a text file and add &lt;strong&gt;sText&lt;/strong&gt; data to that file.&lt;br&gt;{&lt;br&gt;FileInfo temp = new FileInfo("Hello.txt");&lt;br&gt;StreamWriter text = temp.CreateText();&lt;br&gt;text.WriteLine(sText);&lt;br&gt;text.Close();&lt;br&gt;Console.WriteLine(sText);&lt;br&gt;}&lt;/p&gt;
	&lt;/blockquote&gt;
	&lt;p&gt;If you don't use ImpersonationOption.Allowed, It will give impersonation exception.&lt;br&gt;If you are not dealing with the files you don't need to add impersonation property.&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]&lt;br&gt;public string ReadFromFile()&lt;/em&gt; This method will read data from Hello.Txt file and return that string&lt;br&gt;{&lt;br&gt;Console.WriteLine("End of Writing");&lt;br&gt;StreamReader read = File.OpenText("Hello.txt");&lt;br&gt;string sRead = null;&lt;br&gt;sRead = read.ReadLine();&lt;br&gt;if (sRead == null)&lt;br&gt;return "Battula";&lt;br&gt;else&lt;br&gt;return sRead + " Battula";&lt;/p&gt;
	&lt;p&gt;}&lt;/p&gt;
	&lt;/blockquote&gt;
	&lt;p&gt;configuration files contains normal client server configuration. &lt;br&gt;I used &lt;em&gt;netTcpBinding binding&lt;/em&gt;.&lt;/p&gt;
	&lt;p&gt;server configuration file&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;&lt;system.serviceModel&gt;&lt;br&gt;    &lt;behaviors&gt;&lt;br&gt;      &lt;serviceBehaviors&gt;&lt;br&gt;        &lt;behavior name="MetadataBehavior"&gt;&lt;br&gt;          &lt;serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1" maxConcurrentInstances="1"/&gt;&lt;br&gt;          &lt;serviceMetadata httpGetEnabled="true" httpGetUrl="&lt;a href="http://localhost:6010/clsFiles1/"&gt;&lt;a href="http://localhost:6010/clsFiles1/"&gt;http://localhost:6010/clsFiles1/&lt;/a&gt;&lt;/a&gt;" /&gt;&lt;br&gt;        &lt;/behavior&gt;&lt;br&gt;      &lt;/serviceBehaviors&gt;&lt;br&gt;    &lt;/behaviors&gt;&lt;br&gt;    &lt;services&gt;&lt;br&gt;      &lt;service behaviorConfiguration="MetadataBehavior" name="Files1.clsFiles1"&gt;&lt;br&gt;        &lt;endpoint address="" binding="netTcpBinding" bindingConfiguration=""&lt;br&gt;         name="battula" contract="Files1.IFiles1" /&gt;&lt;br&gt;        &lt;endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""&lt;br&gt;         name="ep2" contract="IMetadataExchange" /&gt;&lt;br&gt;        &lt;host&gt;&lt;br&gt;          &lt;baseAddresses&gt;&lt;br&gt;            &lt;add baseAddress="&lt;a href="http://localhost:6010/clsFiles1/"&gt;&lt;a href="http://localhost:6010/clsFiles1/"&gt;http://localhost:6010/clsFiles1/&lt;/a&gt;&lt;/a&gt;" /&gt;&lt;br&gt;            &lt;add baseAddress="net.tcp://localhost:6011/clsFiles1/" /&gt;&lt;br&gt;          &lt;/baseAddresses&gt;&lt;br&gt;        &lt;/host&gt;&lt;br&gt;      &lt;/service&gt;&lt;br&gt;    &lt;/services&gt;&lt;br&gt;  &lt;/system.serviceModel&gt;&lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;The Client Configuration file I used&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt; &lt;system.serviceModel&gt;&lt;br&gt;    &lt;bindings&gt;&lt;br&gt;      &lt;netTcpBinding&gt;&lt;br&gt;        &lt;binding name="battula" closeTimeout="00:01:00" openTimeout="00:01:00"&lt;br&gt;            receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"&lt;br&gt;            transferMode="Buffered" transactionProtocol="OleTransactions"&lt;br&gt;            hostNameComparisonMode="StrongWildcard" listenBacklog="10"&lt;br&gt;            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"&lt;br&gt;            maxReceivedMessageSize="65536"&gt;&lt;br&gt;          &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"&lt;br&gt;              maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;&lt;br&gt;          &lt;reliableSession ordered="true" inactivityTimeout="00:10:00"&lt;br&gt;              enabled="false" /&gt;&lt;br&gt;          &lt;security mode="Transport"&gt;&lt;br&gt;            &lt;transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /&gt;&lt;br&gt;            &lt;message clientCredentialType="Windows" /&gt;&lt;br&gt;          &lt;/security&gt;&lt;br&gt;        &lt;/binding&gt;&lt;br&gt;      &lt;/netTcpBinding&gt;&lt;br&gt;    &lt;/bindings&gt;&lt;br&gt;    &lt;client&gt;&lt;br&gt;      &lt;endpoint address="net.tcp://localhost:6011/clsFiles1/"&lt;br&gt;          binding="netTcpBinding" bindingConfiguration="battula" contract="IFiles1"&lt;br&gt;          name="battula"&gt;&lt;br&gt;        &lt;identity&gt;&lt;br&gt;          &lt;userPrincipalName value="BBO-XP\bbo" /&gt;&lt;br&gt;        &lt;/identity&gt;&lt;br&gt;      &lt;/endpoint&gt;&lt;br&gt;    &lt;/client&gt;&lt;br&gt;  &lt;/system.serviceModel&gt;&lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;  &lt;/p&gt;
	&lt;p&gt;&lt;span&gt;The client apllication what I tested is very simple and basic one. I have two command buttions and two text boxes. One command buttion is create a text file and it can write some content into that text file, that content we have to write in text box.&lt;/p&gt;
	&lt;p&gt;The other command button read data from that text file an write that content into the other text box.&lt;/p&gt;
	&lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;span&gt;Code&lt;/span&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/span&gt; &lt;/p&gt;
	&lt;p&gt;&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;namespace FilesClient&lt;br&gt;{&lt;br&gt;    public partial class Form1 : Form&lt;br&gt;    {&lt;br&gt;        Files1Client m_client = new Files1Client();&lt;br&gt;        public Form1()&lt;br&gt;        {&lt;br&gt;            InitializeComponent();&lt;br&gt;        }
&lt;p&gt;        private void cmdWrite_Click(object sender, EventArgs e)&lt;br&gt;        {&lt;br&gt;            string str = txtWrite.Text;&lt;br&gt;            m_client.WriteToFile(str);&lt;br&gt;        }&lt;/p&gt;
	&lt;p&gt;        private void cmdRead_Click(object sender, EventArgs e)&lt;br&gt;        {&lt;br&gt;            string str =m_client.ReadFromFile();&lt;br&gt;            txtRead.Text = str;&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;Regards&lt;br&gt;Ravi.Battula&lt;/p&gt;
&lt;p&gt; &lt;small&gt; &lt;a href="http://battula32.blog.co.uk/2007/08/14/wcf_impersonation_behavior~2805953/#comments"&gt;Comments&lt;/a&gt; &lt;/small&gt; &lt;/p&gt;</content></entry><entry><id>tag:battula32.blog.co.uk,2007-05-09:/2007/05/09/my_first_vb_blog~2237531/</id><title>My first VB Blog</title><link rel="alternate" type="text/html" href="http://battula32.blog.co.uk/2007/05/09/my_first_vb_blog~2237531/"/><author><name>battula32</name></author><published>2007-05-09T09:18:10+02:00</published><updated>2007-05-09T09:25:03+02:00</updated><content type="html">	&lt;p&gt;It may be very small but useful for VB developers.&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;How to Open ‘ &lt;strong&gt;*&lt;/strong&gt;&lt;strong&gt;*&lt;/strong&gt;*.chm” file using VB&lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;We can’t open  “&lt;strong&gt;*&lt;/strong&gt;.Chm “ just like ****.Hlp file. Because DialogBox can’t open  .Chm files.&lt;/p&gt;
	&lt;p&gt;For Hlp Files&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;DlOpen.HelpFile = “C\Test.Hlp”&lt;br&gt;
DlgOpen.HelpCommand = cdlHelpContents&lt;br&gt;
DlgOpen.ShowHelp&lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;But for .Chm file&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;DlOpen.HelpFile = “C\Test.chm”&lt;/blockquote&gt;
   Will give error.&lt;/p&gt;
	&lt;p&gt;       To Open   .Chm fiels we have to use “Win API calls”&lt;br&gt;
The API which we are going to Use is&lt;br&gt;
“ShellExecute(……………………………..)”&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _&lt;br&gt;
  (ByVal hWnd As Long, ByVal lpOperation As String, _&lt;br&gt;
  ByVal lpFile As String, ByVal lpParameters As String, _&lt;br&gt;
  ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long&lt;/p&gt;
	&lt;p&gt;Const SW_SHOWNORMAL = 1 &lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;In side the code we have to call this.&lt;/p&gt;
	&lt;blockquote&gt;&lt;p&gt;Call ShellExecute(Me.hWnd, "open", g_sHelpDir &amp; "\Test.chm", "", 0, SW_SHOWNORMAL)&lt;/p&gt;&lt;/blockquote&gt;
	&lt;p&gt;Regards&lt;br&gt;
Ravi
&lt;/p&gt;
&lt;p&gt; &lt;small&gt; &lt;a href="http://battula32.blog.co.uk/2007/05/09/my_first_vb_blog~2237531/#comments"&gt;Comments&lt;/a&gt; &lt;/small&gt; &lt;/p&gt;</content></entry></feed>
