Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
176
Seeting focus in first cell of grid?
posted

I am trying to insert a new row in a grid and then set the first cell automatically to edit mode. The rows in my grid are inserted via databinding to a business object, and not directly to the grid from a button's click. i.e.  a row insert is done by adding a new business object  into the datasource and then binding it to the grid.

I tried to set the focus by writing the code in load, paint, button click etc., but not successfull, the row is highlighted but no cell is in edit mode. If I first click on the grid and then inserts a new row it works for every new row thereafter.

I found a similar post(having same problem) in the forums - http://community.infragistics.com/forums/t/7935.aspx?PageIndex=1

None of the ways suggested in above post is usefull for me, like -

            this.grid.Focus();
            this.grid.Rows.FilterRow.Cells["Name"].Activate();
            this.grid.PerformAction(UltraGridAction.FirstCellInRow);
            this.grid.PerformAction(UltraGridAction.EnterEditMode);
or

 private void button1_Click(object sender, EventArgs e)
        {

// Code to add a new object in the collection and do data bind

userCotrol.setFocus();

}

public void setFocus()

{

 this.BeginInvoke(new MethodInvoker(this.SetFocusToFirstCell))

}

        private void SetFocusToFirstCell()
        {
            System.Threading.Thread.Sleep(200);
            this.grid.Focus();
            this.grid.ActiveCell = this.grid.Rows.FilterRow.Cells["Name"];
            this.grid.PerformAction(UltraGridAction.EnterEditMode);

       }

My grid is in a user control and button is on the form, I also checked the cell for it's readonly attribute and that was fine, can any body point out why it's not happening for me?

-Anand

Parents Reply Children
No Data