[RESOLVED] How to restrict a user to enter particular DataGridView Column?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] How to restrict a user to enter particular DataGridView Column?

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    53

    [RESOLVED] How to restrict a user to enter particular DataGridView Column?

    Hi, I wish to restrict columns for user entries. While the users click or enters into Column_1 or Column_2, I wish to focus to a cell in same row & column_3.So I tried by the following ways, it's not succeeded...

    It's giving "Re-Entrant call to a SetCurrentCellAddress Core function", error...

    Note : May be Column-3 is DataGridViewComboBox Column....

    Thanks for the helps

    private: System::Void MyDataGrid1_CellEnter(System::Object^ Sender, System::Windows::Forms:ataGridViewCellEventArgs^ e) {
    if (e->RowIndex>0 && (e->ColumnIndex==1 || e->ColumnIndex==2)) {
    myDataGrid1->ClearSelection();
    myDataGrid1->Rows[myDataGrid1->CurrentCell->RowIndex]->Cells[3]->Selected = true;
    myDataGrid1->SelectionMode = DataGridViewSelectionMode::CellSelect;
    myDataGrid1->MultiSelect = false;
    }
    }

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,594

    Re: How to restrict a user to enter particular DataGridView Column?

    I'd suggest you carefully examine the call stack displayed when the exception gets thrown. This may give invaluable hints how you can reslolve the issue.

    It may already help to handle a different event to pursue your goal, like SelectionChanged or CurrentCellChanged (admittedly, these two don't really get passed much useful inforation as their parameters, just the DGV itself as sender) or CellStateChanged. A strategically placed re-entry guard using a bool flag may also help. And as a last resort I can think of deriving your own class from DataGridView and overriding SetCurrentCellAddressCore(), perhaps iplementing a re-entry guard there, though this may get a bit hackish.

    Finally, a bit of code simplification may already resolve the conflict. For instance, do you really need to set myDataGrid1->SelectionMode here? I don't actually think this particular instruction is the culprit, just as an example.

    HTH
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Dec 2011
    Posts
    53

    Re: How to restrict a user to enter particular DataGridView Column?

    Thanks Eri, I solve by the following way

    private: System::Void MyDataGrid1_EditingControlShowing(System::Object^ Sender, DataGridViewEditingControlShowingEventArgs^ e) {
    if (myDataGrid1->CurrentCell->ColumnIndex == 1 || myDataGrid1->CurrentCell->ColumnIndex == 2 ) {
    myDataGrid1->EditingControl->KeyPress -= gcnew KeyPressEventHandler(this, &Form1::EditingControl_KeyPress);
    myDataGrid1->EditingControl->KeyPress += gcnew KeyPressEventHandler(this, &Form1::EditingControl_KeyPress);
    }
    }
    private: System::Void EditingControl_KeyPress(System::Object^ Sender, KeyPressEventArgs^ e) {
    if (myDataGrid1->CurrentCell->ColumnIndex == 1 || myDataGrid1->CurrentCell->ColumnIndex == 2) {
    myDataGrid1->Rows[myDataGrid1->CurrentCell->RowIndex]->Cells[4]->Selected = true;
    e->Handled = true;
    }
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center