Datagridview 在文本框中显示选定单元格的行和列值
我试图获取一个DataGridView来显示用户所选单元格所在的行和列中的HeaderText。但到目前为止,我只能得到所选单元格内的值。我知道C中更容易做到这一点,但它是C++的练习。 到目前为止,我所拥有的:Datagridview 在文本框中显示选定单元格的行和列值,datagridview,visual-c++-2010,Datagridview,Visual C++ 2010,我试图获取一个DataGridView来显示用户所选单元格所在的行和列中的HeaderText。但到目前为止,我只能得到所选单元格内的值。我知道C中更容易做到这一点,但它是C++的练习。 到目前为止,我所拥有的: private: System::Void addAsDestinationCellToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { if(DGV->CurrentCel
private: System::Void addAsDestinationCellToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
if(DGV->CurrentCell != nullptr)
{
String^ t = dynamic_cast<String^>(DGV->CurrentCell->Value);
dText->Text = t;
}
}
您需要做的是获取当前单元格的列索引值,并使用该值在DataGridView中获取该列的HeaderText 代码如下:
String^ t = DGV->Columns[DGV->CurrentCell->ColumnIndex]->HeaderText;
String^ t = DGV->Columns[DGV->CurrentCell->ColumnIndex]->HeaderText;