如何在SelectedIndex中将DataGridView ComboBoxColumn更改为TextBoxCell?

人气:448 发布:2022-09-22 标签: c++

问题描述

嗨 从以下代码,我有DataGridViewComboBox专栏... ReligionClm ... 并有一个dataRow文本添加新项目...... 我的意图是,当用户选择其他行时,则没问题。但是,一旦用户选择添加新项目,则ComboBox需要将其更改为TextBoxCell ...以阅读新项目。 我尝试从ComboBox_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 My Codes

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....
}
}

推荐答案

Hi 为什么这样做你想在selectedindexchanged()中做这个吗? 你可以通过edditing dataviewgrid Template.try来做到这一点。 你的Farhad。 Hi Why do you want to do this in selectedindexchanged()? You do thus by edditing dataviewgrid Template.try it. Yours Farhad.

236