一、PopList控件实现通用选择难点:
1.1通用加载过程;一层加与两层加载;
1.2选择结果分配;
二、过程实现
2.1数据加载过程的实现
public static Boolean PopListCommAddList(PopList Vlist, String GSQL, String GItrmFld, String LSQL, String LItrmFld, String GrpText, Boolean MulSel, Boolean SngSelMode )
{
//功能:PopList通用加载过程
Boolean blnOK = false;
string MTTYItem = "",SSQL="";
if (GSQL.Trim() == "") //只有一个Group GrpText
{
PopListGroup plg = new PopListGroup() { Title = "" + GrpText, TitleVisible = true };
SSQL = LSQL;
DataSet dsCangzhi = SqlHelper.Ex_Query(LSQL);
if (dsCangzhi.Tables[0].Rows.Count > 0)
{
for (int J = 0; J <= dsCangzhi.Tables[0].Rows.Count - 1; J++)
{
MTTYItem = dsCangzhi.Tables[0].Rows[J][LItrmFld].ToString();
plg.Items.Add(new PopListItem("" + MTTYItem));
}
}
Vlist.Groups.Add(plg);
}
else
{
Vlist.Groups.Clear();
Vlist.MultiSelect = MulSel; //可以多选择
Vlist.SingleSelectMode = SngSelMode; //去掉单选模式
DataSet dsFirstZM = SqlHelper.Ex_Query(GSQL);
if (dsFirstZM.Tables[0].Rows.Count > 0)
{
for (int I = 0; I <= dsFirstZM.Tables[0].Rows.Count - 1; I++)
{
MTTYItem = dsFirstZM.Tables[0].Rows[I][GItrmFld].ToString();
PopListGroup plg = new PopListGroup() { Title = "" + MTTYItem, TitleVisible = true }; //pl.Groups.
//"SELECT DEF_STOCKADD_ID+'-'+DEF_STOCKADD_DESC AS [ADDLIST] FROM DEF_STOCKADD WHERE DEF_STOCKADD_ID LIKE '" + MTTYItem + @"%' AND DEF_STOCKADD_TYPE='1' ORDER BY DEF_STOCKADD_ID"
SSQL = LSQL.Replace("@GPID", MTTYItem);
DataSet dsCangzhi = SqlHelper.Ex_Query(LSQL);
if (dsCangzhi.Tables[0].Rows.Count > 0)
{
for (int J = 0; J <= dsCangzhi.Tables[0].Rows.Count - 1; J++)
{
MTTYItem = dsCangzhi.Tables[0].Rows[J][LItrmFld].ToString();
plg.Items.Add(new PopListItem("" + MTTYItem));
}
}
Vlist.Groups.Add(plg);
}
}
}
return blnOK;
}
2.2选择结果的分配
2.2.A,加载过程要定义选择窗口标题
private void btnADD_Press(object sender, EventArgs e)
{
string ASQL= "SELECT DEF_STOCKADD_ID+'-'+DEF_STOCKADD_DESC AS [ADDLIST] FROM DEF_STOCKADD INNER JPDYL_ADDR ONOIN DEF_STOCKADD.DEF_STOCKADD_ID=PDYL_ADDR.PDYL_ADDRID WHERE PDYL_ADDR.PDYL_M_ID= '" + PDID + @"' AND DEF_STOCKADD.DEF_STOCKADD_TYPE='1' ORDER BY DEF_STOCKADD_ID"
SqlHelper.PopListCommAddList(this.pL1,"", "", ASQL, "ADDLIST", "仓址列表",false,true);
pL1.Title = "仓址选择";
pL1.Show();
}
2.2.B,选择结果分配:通过识别标题
private void pL1_Selected(object sender, EventArgs e)
{
switch(pL1.Title)
{
case "仓址选择": //仓址选择 单选
txtADDR.Text = this.pL1.Selection.Text;
break;
case "":
break;
}
}