QwYko
QwYko
采纳率100%
2019-11-20 15:09

lookupedit控件中用EditValueChanged事件完成省市联动,为什么选择几次省就会出现几次市?(多次选择市之后区也是这个问题),怎么解决?

已结题

lookupedit控件中用EditValueChanged事件完成省市联动,为什么选择几次省就会出现几次市?(多次选择市之后区也是这个问题),怎么解决?

图片说明

private void sheng_EditValueChanged(object sender, EventArgs e)
        {
            DataTable shiTb = SqlHelper.Query(" select org_id,gw_organization.`name` as org_name FROM gw_organization where length(org_id)=4 and org_id like '" + sheng.EditValue + "%' ", 0);
            if (shiTb != null)
            {
                this.shi.Properties.ValueMember = "org_id";
                this.shi.Properties.DisplayMember = "org_name";
                this.shi.Properties.DataSource = shiTb;
                this.shi.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
                this.shi.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(this.shi.Properties.DisplayMember));


                if (!string.IsNullOrEmpty(_addr.City))
                {
                    var InitValue = from r in shiTb.AsEnumerable()
                                    where r.Field<string>("org_name") == _addr.City
                                    let objectArray = new object[]
                                    {
                                    r.Field<string>("org_id")
                                    }
                                    select objectArray;
                    shi.EditValue = InitValue.ToList()[0][0];
                }
            }
        }
private void shi_EditValueChanged(object sender, EventArgs e)
        {
            DataTable quTb = SqlHelper.Query(" select org_id,gw_organization.`name` as org_name FROM gw_organization where length(org_id)=6 and org_id like '" + shi.EditValue + "%' ", 0);
            if (quTb != null)
            {
                this.qu.Properties.ValueMember = "org_id";
                this.qu.Properties.DisplayMember = "org_name";
                this.qu.Properties.DataSource = quTb;
                this.qu.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
                this.qu.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(this.qu.Properties.DisplayMember));

                if (!string.IsNullOrEmpty(_addr.District))
                {
                    var InitValue = from r in quTb.AsEnumerable()
                                    where r.Field<string>("org_name") == _addr.District
                                    let objectArray = new object[]
                                    {
                                    r.Field<string>("org_id")
                                    }
                                    select objectArray;
                    qu.EditValue = InitValue.ToList()[0][0];
                }
            }
        }
  • 点赞
  • 收藏
  • 复制链接分享

1条回答

  • chenbeifang chenbeifang 2年前

    Add前 先进行Clear

    点赞 评论 复制链接分享