0

Reg windows forms syncfusion, grid control 我正在尝试添加一个弹出框,就像我们在 xcel 中的弹出框一样。在右键单击单元格然后插入时,会出现一个小弹出框,询问需要插入多少行。

所以这就是我所做的

private void InsertRowToolStripMenuItem_Click(object sender, EventArgs e)
        {
           GridRangeInfoList list;

            list  = theGrid.Selections.GetSelectedRows(true, false);
            int rowNumber = list.ActiveRange.Top;
            Panel box = new Panel(); //
            NumericUpDown ud1 = new NumericUpDown(); 

            ud1.Dock = DockStyle.Left;  ud1.Width = 30; 
            ud1.BorderStyle = BorderStyle.FixedSingle;
            box.Controls.Add(ud1); 
            box.BorderStyle = BorderStyle.None;
            Button btn = new Button();
            btn.Dock = DockStyle.Bottom;
            btn.Text = "OK";
            box.Controls.Add(btn);

            this.Controls.AddRange(new System.Windows.Forms.Control[] { box }); 
            btn.Click += new EventHandler(btn_Click);
            theGrid.Controls.Add(box);
            box.Dock = DockStyle.Bottom;
            box.Show();
            numberOfRowstobeInserted = (int)ud1.Value;
            this.Controls.Add(box); 
            theData.CreateRowsToInsert(rowNumber, numberOfRowstobeInserted);

            theGrid.Refresh();
}

但是这种添加带有数字上下的面板的方式似乎不起作用。基本上,一旦单击插入,我想要一个带有数字上下和按钮的小窗口/面板。用户从上/下选择一个值,然后单击确定按钮。

有什么建议么?

谢谢孙

4

1 回答 1

0

您可以处理以下修改后的代码以使其正常工作。

    private Panel box;
    private NumericUpDown ud1;
    private Button btn;        
    int rowNumber, rowIndex, colIndex;
    GridStyleInfo style;

    void ContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
    {
        rowNumber = this.gridGroupingControl1.Table.CurrentRecord.GetSourceIndex();
        rowIndex = this.gridGroupingControl1.TableControl.CurrentCell.RowIndex;
        colIndex = this.gridGroupingControl1.TableControl.CurrentCell.ColIndex;
        style = this.gridGroupingControl1.TableControl.GetViewStyleInfo(rowIndex,colIndex);
        box = new Panel(); // 
        ud1 = new NumericUpDown();

        ud1.Location = new Point(15, 15);
        ud1.Size = new Size(50, 10);
        ud1.BorderStyle = BorderStyle.FixedSingle;
        box.Controls.Add(ud1);
        box.BorderStyle = BorderStyle.None;

        btn = new Button();
        btn.Location = new Point(30, 50);
        btn.Size = new Size(30,20);
        btn.Text = "OK";
        btn.Click += new EventHandler(btn_Click);
        box.Controls.Add(btn);

        box.Location = this.gridGroupingControl1.TableControl.CurrentCell.Renderer.GetCellLayout(rowIndex, colIndex, style).ClientRectangle.Location;
        box.Size = new Size(80, 70);

        this.gridGroupingControl1.Controls.Add(box);
        box.Show();
        box.BringToFront();
    }

    void btn_Click(object sender, EventArgs e)
    {
        int numberOfRowstobeInserted = (int)ud1.Value;
        DataTable dt = (this.gridGroupingControl1.DataSource as DataView).Table;
        for (int count = 0; count < numberOfRowstobeInserted; count++)
        {
            DataRow dr = dt.NewRow();
            for (int i = 0; i < dt.Columns.Count; i++)
                dr[i] = 0; //default value
            dt.Rows.InsertAt(dr, rowNumber++);
        }
        box.Dispose();
    }
于 2012-06-19T11:05:30.103 回答