[RESOLVED] How to change DataGridView ComboBoxColumn-as TextBoxCell-in SelectedIndex ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] How to change DataGridView ComboBoxColumn-as TextBoxCell-in SelectedIndex ?

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    53

    [RESOLVED] How to change DataGridView ComboBoxColumn-as TextBoxCell-in SelectedIndex ?

    Hi
    From the below codes, I have DataGridViewComboBox Column...ReligionClm...
    and have a dataRow text "Add New Item"...

    My intention is, while the user select other rows, then no problem. But, once the user
    select "Add New Item" then the ComboBox need to change it as TextBoxCell...to read the new item.

    I tried from ComboBox_SelectedIndex() I have not succeeded... Any changes with my code will be great

    Form_Load(){
    DataGridViewComboBoxColumn^ ReligionClm = gcnew DataGridViewComboBoxColumn();
    this->myDataGrid1->Columns->Remove("religion");
    this->myDataGrid1->Columns->Insert(5, ReligionClm);
    this->myDataGrid1->Columns[5]->Name = "religion";
    }

    System::Void MyDataGrid1_EditingControlShowing() {
    ComboBox^ ComBox = dynamic_cast<ComboBox^>(e->Control);
    ComBox->SelectedIndexChanged += gcnew EventHandler(this, &Form_Form1::EmpCmb_SelectedIndexChanged);
    }

    System::Void EmpCmb_SelectedIndexChanged() {
    if (myDataGrid1->CurrentRow->Cells["religion"]->Value=="Add New Item"){
    DataGridViewTextBoxCell^ TxtBoxCell = gcnew DataGridViewTextBoxCell();
    myDataGrid1[5, myDataGrid1->CurrentCell->RowIndex] = TxtBoxCell;
    ??????????? Any Chnages will be helpful....
    }
    }

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

    Re: How to change DataGridView ComboBoxColumn-as TextBoxCell-in SelectedIndex ?

    How would you ever expect that to compile!? Parameterless event handlers? Then using the e parameter that doesn't get passed at all? And your Form_Load() doesn't have the void return type specified... Also, please use code tags when posting code.

    Even if it (seemingly) works, I don't think replacing the combo box DGV cell with a text box cell on the fly is a viable approach. After all, you want to have the combo box cell back in place after the user has added the new item, right? So I'd suggest to rather leave the original cell object in place.

    The cleanest solution probably would be to derive your own DGV cell type that manifests either as a combo box or text box cell, depending on its state. I'd expect that to be quite some effort, though.

    A simpler approach, I think, is to overlay the selected combo box cell with an ordinary TextBox control (i.e. not a DGV cell) you create (or just position) on the fly to let the user enter the new item there. A bit tricky with that approach may be properly catching the Enter keystroke when the user submits the new item, so it doesn't dismiss the entire form containing the DGV. The same applies to an Esc keystroke to cancel entry of the new item. And you'll probably want to keep the user from simply tabbing out of the floating text box instead if submitting or canceling the edit.
    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 change DataGridView ComboBoxColumn-as TextBoxCell-in SelectedIndex ?

    Thanks Eri.....I get clear ......Thanks Again

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center