how to avoid the repeated code to increase the efficiency <p>I have a <code>DataGrid</code> view1 and a <code>ListView</code> and when ever I select the list view item(I am passing the <code>ListView</code> item into the query and populating the <code>DataGrid</code> view according that item) </p> <p>I have wrote some code like this....</p> <pre><code> private void listview_selectedindexchanged(object sender event args) { if (listview.SelectedItems.Count &gt; 0 &amp;&amp; listview.SelectedItems[0].Group.Name == "abc") { if(lstview.SelectedItems[0].Text.ToString() == "sfs") { method1(); } else { // datagrid view1 binding blah..... } } if (lstview.SelectedItems.Count &gt; 0 &amp;&amp; lstview.SelectedItems[0].Group.Name == "def") { if(lstview.SelectedItems[0].Text.ToString() == "xyz") { method 1(); } if(lstview.SelectedItems[0].Text.ToString() == "ghi") { method 2(a,b); } if(lstview.SelectedItems[0].Text.ToString() == "jkl") { method 2(c,d); } if(lstview.SelectedItems[0].Text.ToString() == "mno") { method 3(); } } } private void method 1() { // datagrid view1 binding blahh } private void method 2(e,g) { // datagrid view1 binding blah....blah.. } private void method 3() { // datagrid view1 binding } </code></pre> <p>I have done it like above ... I think this is not an efficient way to do the coding. and this code consisits of a lot of repeated lines, is there any way to refractor this code to a small bunch of code ...... in order improve the efficiency? </p> <p>Any ideas and sample snippets for increasing code efficiency would be helpful to me ...</p> <p>Many thanks in advance....</p> <p>I am using c# and writting WinForms applications.....</p>