0

I have a customtextbox and a customdatagridview . the customtextbox on its OnKeyDown event behaving as tab and on its back key behaving as reverse tab respectively . Now on my customdatagridview's OnEnter, I want to analyze which customtextbox is sending the focus to customdatagridview so that I change my current cell accordingly , but I am confused as how to get it .

public partial class betterdatagridview : DataGridView
    {
    protected override void OnEnter(EventArgs e)
    {
        // datagridview has data 
        if (this.RowCount > 0)
        {

            if () // what to place here to check which customtextbox send me here 
            {
                this.CurrentCell = this.Rows[0].Cells[0]; // select the first cell in the first row
            }
            else if()
            {
                this.CurrentCell = this.Rows[RowCount - 1].Cells[0];//[0, this.RowCount - 1]; // select the last row's first cell
            }
         
            this.BeginEdit(true); // it must stay here 
            TextBox textBox = (TextBox)this.EditingControl; // Cast the EditingControl to TextBox
            textBox.SelectionStart = textBox.Text.Length; // select the textbox from last 
            
        }

and below is the customtextbox

  protected override void OnKeyDown(KeyEventArgs e)
    {
        if (!DisableFeatures)
        {
            if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Down)&& this.Text !="")
            {
                e.Handled = true;
                e.SuppressKeyPress = true;
                TriggerEvent?.Invoke(Last, Name);
                if (!Last)
                {
                    SendKeys.Send("{TAB}");
                }
               
                return;
            }
            if ((e.KeyCode == Keys.Back || e.KeyCode == Keys.Up) && this.Text.Length == 0)
            {
                SendKeys.Send("+{TAB}");
            }
        }
        base.OnKeyDown(e);          
    }
3
  • Try this.RowIndex and this.ColumnIndex. Commented Jul 20, 2023 at 12:47
  • @jdweng , what ? are you serious . rowindex and columnindex ??? Commented Jul 20, 2023 at 14:54
  • "This" is the object DataGridviewCell. You are editing a custom textbox in the cell. The cell has a row index and a column index. Commented Jul 20, 2023 at 15:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.