我有<条码>DataGrid view1和ListView
,而且我从未选择过名单(我通过<条码>)。 清单: 列入<代码>DataGrid的物项,根据该项目
我已经写过这样的一些法典。
private void listview_selectedindexchanged(object sender event args)
{
if (listview.SelectedItems.Count > 0 && listview.SelectedItems[0].Group.Name == "abc")
{
if(lstview.SelectedItems[0].Text.ToString() == "sfs")
{
method1();
}
else
{
// datagrid view1 binding
blah.....
}
}
if (lstview.SelectedItems.Count > 0 && 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
}
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?
任何提高守则效率的想法和样本都对我有帮助。
许多预告......。
我正在使用C#和WinForms的申请。