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
40
wingrid cell: How To make the cell behave like an excel cell.
posted

The goal is, if there is on an editible cell, and the user starts typing, the cell should go in edit mode and accept the typed contents.

I am using the following code (the key_press is not behaving properly.. is there a better method):

private void grdMarkPrice_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Enter)

{

if (this.grdMarkPrice.ActiveCell != null

&& this.grdMarkPrice.ActiveCell.Column.Header.Caption == "MarkPrice"

&& this.grdMarkPrice.ActiveCell.CanEnterEditMode)

{

if (!this.grdMarkPrice.ActiveCell.IsInEditMode)

{

this.grdMarkPrice.PerformAction(UltraGridAction.EnterEditMode, false, false);

}

else

{

this.grdMarkPrice.PerformAction(UltraGridAction.ExitEditMode, false, false);

this.grdMarkPrice.PerformAction(UltraGridAction.BelowCell, false, false);

this.grdMarkPrice.PerformAction(UltraGridAction.EnterEditMode, false, false);

}

}

}

}

private void grdMarkPrice_KeyPress(object sender, KeyPressEventArgs e)

{

try

{

if (this.grdMarkPrice.ActiveCell != null

&& this.grdMarkPrice.ActiveCell.Column.Header.Caption == "MarkPrice"

&& this.grdMarkPrice.ActiveCell.CanEnterEditMode&& !this.grdMarkPrice.ActiveCell.IsInEditMode)

{

long result;

if (Int64.TryParse(Convert.ToString(e.KeyChar), out result))

{

Debug.WriteLine("grdMarkPrice_KeyPress " + e.KeyChar + " " + DateTime.Now.ToLongTimeString());

this.grdMarkPrice.ActiveCell.Column.Format = "";

this.grdMarkPrice.PerformAction(UltraGridAction.EnterEditMode, false, false);

this.grdMarkPrice.ActiveCell.Value = result;

this.grdMarkPrice.ActiveCell.SelStart = 10;

}

}

} catch{ } }

Parents
No Data
Reply
  • 9298
    posted

    I suggest that you put the editable cell into edit mode any time you active a row.  That way when the user starts typing the text that he types will go into the cell.  So you could handle the AfterRowActivate event and then activate the editable cell and then call the PerformAction method to put the cell into edit mode.  You will also need to call  the PerformAction method again in the AfterSelectChange event, otherwise the cell will go out of edit mode.  I am attaching to this forum thread a sample which demonstrates how this can be done.  I hope you find it helpful.

    ActivationDemo.zip
Children
No Data