adding a numericup down in a syncfusion grid control

Go To StackoverFlow.com

0

Reg windows forms syncfusion, grid control I am trying to add a popup box like the one we have in xcel. On rightclicking a cell and then insert, a small popup box asking how many rows needs to be inserted.

So this is what I have done

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();
}

But this way of adding a panel with a numeric updown doesn't seem to work. Basically, once the click on insert, I want a small window/panel wiht a numeric updown and a Button. The user selects a value from the up/down and then clicks the ok button.

Any suggestions?

Thanks Sun

2012-04-05 16:52
by user575219


0

You can handle the following revised code to get it working.

    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-19 11:05
by Rajadurai C
Ads