您的位置:首页 > 编程语言 > C#

C# Devexpress gridControl 自定义编辑器 设置弹出框(弹出框包含gridLookUpEdit)

2016-03-09 14:42 726 查看
  关于Dev 的GridControl如何自定义弹出框式编辑器(弹出框中包含)gridLookUpEdit的问题

            // ----------设置弹出框的样式
                    //桩号下拉框选择

                    RepositoryItemGridLookUpEdit gridLookUpEdit = new RepositoryItemGridLookUpEdit();

                    gridLookUpEdit.PopupFilterMode = PopupFilterMode.Contains;//包含即可

                    gridLookUpEdit.ImmediatePopup = true;//是否马上弹出窗体

                    gridLookUpEdit.ValidateOnEnterKey = true;//回车确认

                    gridLookUpEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//文本框可输入

                    gridLookUpEdit.NullText = "";

                    gridLookUpEdit.NullValuePrompt = "";

                    //下拉内容加载

                    DataTable ptSource = new DataTable();

                    ptSource.Columns.Add("桩号");

                    ptSource.Columns.Add("里程");

                    IList<Marker> markerList = SystemEnvironment.GetInstance().MarkerList;

                    if (markerList != null)

                    {

                        foreach (Marker marker in markerList)

                        {

                            DataRow row = ptSource.NewRow();

                            row["桩号"] = marker.NAME;

                            row["里程"] = marker.STATION / 1000.0;

                            ptSource.Rows.Add(row);

                        }

                        gridLookUpEdit.DataSource = ptSource;

                    }

                    gridLookUpEdit.ValueMember = "桩号";

                    gridLookUpEdit.DisplayMember = "桩号";

                    //弹出控件

                    RepositoryItemPopupContainerEdit popupContainerEdit = new RepositoryItemPopupContainerEdit();

                    popupContainerEdit.PopupControl = new PopupContainerControl();

                    popupContainerEdit.QueryPopUp += new CancelEventHandler(markerPopupContainerEdit_QueryPopUp);

                    //弹出控件中加载的控件

                    VGridControl gc = new VGridControl();

                    DevExpress.XtraVerticalGrid.Rows.EditorRow markerRow = new DevExpress.XtraVerticalGrid.Rows.EditorRow();

                    markerRow.Properties.Caption = "桩号";

                    markerRow.Properties.RowEdit = gridLookUpEdit;

                    gc.Rows.Add(markerRow);

                    DevExpress.XtraVerticalGrid.Rows.EditorRow offsetRow = new DevExpress.XtraVerticalGrid.Rows.EditorRow();

                    offsetRow.Properties.Caption = "偏移量(米)";

                    //偏移量为数值类型

                    RepositoryItemSpinEdit spinItem = new RepositoryItemSpinEdit();

                    spinItem.EditValueChanged += new EventHandler(spinItem_EditValueChanged);

                    spinItem.Buttons[0].Visible = false;

                    offsetRow.Properties.RowEdit = spinItem;

                    gc.Rows.Add(offsetRow);

                    gc.Height = 60;

                    popupContainerEdit.PopupControl.Controls.Add(gc);

                    //两个按钮放在panel上固定位置

                    Panel botoomPanel = new Panel();

                    SimpleButton markerOK = new SimpleButton();

                    markerOK.Text = "确定";

                    markerOK.Click += new EventHandler(markerOK_Click);

                    botoomPanel.Controls.Add(markerOK);

                    markerOK.Location = new System.Drawing.Point(markerOK.Location.X + 15, markerOK.Location.Y);

                    SimpleButton markerClear = new SimpleButton();

                    markerClear.Text = "清除";

                    markerClear.Click += new EventHandler(markerClear_Click);

                    markerClear.Location = new System.Drawing.Point(markerOK.Location.X + 100, markerOK.Location.Y);

                    botoomPanel.Controls.Add(markerClear);

                    botoomPanel.Height = markerOK.Height;

                    popupContainerEdit.PopupControl.Height = gc.Height + 30;

                    botoomPanel.Parent = popupContainerEdit.PopupControl;

                    botoomPanel.Dock = DockStyle.Bottom;

                    popupContainerEdit.PopupControl.Controls.Add(botoomPanel);

                    gvData.Columns[fieldIndex].ColumnEdit = popupContainerEdit;

        /// <summary>

        /// “桩号+偏移量”确定,赋值给文本框

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        void markerOK_Click(object sender, EventArgs e)

        {

            NormSegment segment = vList.GetRowValue(gvData.FocusedRowHandle, vList.ColumnCount - 1) as NormSegment;

            if (null == segment) return;

            int fieldIndex = segment.GetColumnIndex(gvData.FocusedColumn.FieldName, true);

            if (-1 == fieldIndex) return;

            SimpleButton markerOK = (SimpleButton)sender;

            VGridControl gc = markerOK.Parent.Parent.Controls[0] as VGridControl;

            MarkerHelper markerConvert = new MarkerHelper();

            if (gc.Rows[0].Properties.Value != null && gc.Rows[0].Properties.Value.ToString() != "")

            {

                //获取单元格的值,把桩号+偏移量转换为里程

                string marker = gc.Rows[0].Properties.Value.ToString();

                string offset = gc.Rows[1].Properties.Value.ToString() == "" ? "0" : gc.Rows[1].Properties.Value.ToString();

                MarkerPoint point = new MarkerPoint(marker, offset);

                double station = markerConvert.MarkerToStation(point);

                //如果里程值未变,不更新

                if (fieldIndex == 1)//起始里程

                {

                    if (vList.GetRowValue(gvData.FocusedRowHandle, 0) != null && station == double.Parse(vList.GetRowValue(gvData.FocusedRowHandle, 0).ToString()))

                        return;

                }

                if (fieldIndex == 3)//结束里程

                {

                    if (vList.GetRowValue(gvData.FocusedRowHandle, 3) != null && station == double.Parse(vList.GetRowValue(gvData.FocusedRowHandle, 2).ToString()))

                        return;

                }

                //如果里程大于最大值,小于最小值,直接赋值为最大值或者最小值

                if (segment.Fields[fieldIndex - 1].FieldMin >= 0 && segment.Fields[fieldIndex - 1].FieldMax > segment.Fields[fieldIndex - 1].FieldMin)

                {

                    if (station > Convert.ToDouble(segment.Fields[fieldIndex - 1].FieldMax))

                    {

                        station = Convert.ToDouble(segment.Fields[fie
bc7e
ldIndex - 1].FieldMax);

                        point = markerConvert.StationToMarker(station);

                    }

                    if (station < Convert.ToDouble(segment.Fields[fieldIndex - 1].FieldMin))

                    {

                        station = Convert.ToDouble(segment.Fields[fieldIndex - 1].FieldMin);

                        point = markerConvert.StationToMarker(station);

                    }

                }

                //为单元格赋值

                string value = point.MarkerName + " + " + point.Offset;

                PopupContainerControl popupContainerControl = gc.Parent as PopupContainerControl;

                popupContainerControl.OwnerEdit.EditValue = value;

                popupContainerControl.OwnerEdit.ClosePopup();

                //更新桩号列

                vList.SetRowValue(gvData.FocusedRowHandle, fieldIndex, value);

                SetForcusRowValue(gvData.FocusedRowHandle, gvData.FocusedColumn.FieldName, value, true);

                SetForcusRowValue(gvData.FocusedRowHandle, gvData.FocusedColumn.FieldName, value, false);

                CheckRowStatus(gvData.FocusedRowHandle);

                //更新里程列

                vList.SetRowValue(gvData.FocusedRowHandle, fieldIndex - 1, station);

                SetForcusRowValue(gvData.FocusedRowHandle, fieldIndex - 1, station.ToString(), true);

                SetForcusRowValue(gvData.FocusedRowHandle, fieldIndex - 1, station.ToString(), false);

                //如果更新的为全局,并且更新结束里程

                if (IsScene)

                    return;

                if (3 == fieldIndex && station < segment.Fields[fieldIndex - 1].FieldMax)//如果改变的是结束里程

                {

                    if (vList.RecordCount >= gvData.FocusedRowHandle + 1)//确保下面还有一个空行

                    {

                        //更新桩号列

                        vList.SetRowValue(gvData.FocusedRowHandle + 1, 1, value);

                        SetForcusRowValue(gvData.FocusedRowHandle + 1, 1, value, true);

                        SetForcusRowValue(gvData.FocusedRowHandle + 1, 1, value, false);

                        CheckRowStatus(gvData.FocusedRowHandle);

                        //更新里程列

                        vList.SetRowValue(gvData.FocusedRowHandle + 1, 0, station);

                        SetForcusRowValue(gvData.FocusedRowHandle + 1, 0, station.ToString(), true);

                        SetForcusRowValue(gvData.FocusedRowHandle + 1, 0, station.ToString(), false);

                        NormSegment nextSegment = vList.GetRowValue(gvData.FocusedRowHandle + 1, vList.ColumnCount - 1) as NormSegment;

                        if (NormSegment.RecordStatus.NewNoModify == nextSegment.RowStatus)

                        {

                            vList.SetRowValue(gvData.FocusedRowHandle + 1, 2, segment.Fields[2].FieldMax);//结束里程

                            SetForcusRowValue(gvData.FocusedRowHandle + 1, 2, segment.Fields[2].FieldMax.ToString(), false);

                            SetForcusRowValue(gvData.FocusedRowHandle + 1, 2, segment.Fields[2].FieldMax.ToString(), true);

                        }

                        if (NormSegment.RecordStatus.LoadWithNoModify == nextSegment.RowStatus)

                        {

                            CheckRowStatus(gvData.FocusedRowHandle + 1);

                        }

                    }

                }

                NormSegment nextRow = vList.GetRowValue(gvData.FocusedRowHandle + 1, vList.ColumnCount - 1) as NormSegment;

                if (segment.GetColumnValue(2, false).ToString() == Settings.Default["EndStation"].ToString() && nextRow.RowStatus == NormSegment.RecordStatus.NewNoModify &&

                   nextRow.GetColumnValue(2, false).ToString() == Settings.Default["EndStation"].ToString())

                {

                    //vList.RemoveAt(gvData.FocusedRowHandle + 1);

                    DeleteRow(gvData.FocusedRowHandle + 1);

                }

                CheckRowStatus(gvData.FocusedRowHandle);

            }

        }

        /// <summary>

        /// 桩选择下拉框展开时,赋值桩号和偏移量

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        void markerPopupContainerEdit_QueryPopUp(object sender, CancelEventArgs e)

        {

            PopupContainerEdit popupContainerEdit = sender as PopupContainerEdit;

            PopupContainerControl popupControl = popupContainerEdit.Properties.PopupControl as PopupContainerControl;

            VGridControl gc = popupControl.Controls[0] as VGridControl;

            if (popupContainerEdit.OldEditValue != null && popupContainerEdit.OldEditValue.ToString() != "")

            {

                MarkerPoint point = new MarkerHelper().getMarkerPoint(popupContainerEdit.OldEditValue.ToString());

                //桩号回显

                if (point.MarkerName == null || point.MarkerName == "")

                    gc.Rows[0].Properties.Value = "";

                else

                {

                    gc.Rows[0].Properties.Value = point.MarkerName;

                }

                gc.Rows[1].Properties.Value = point.Offset;

            }

            else

            {

                gc.Rows[0].Properties.Value = "";

                gc.Rows[1].Properties.Value = 0;

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# DEvExpress gridControl