0

我正在尝试获取一个 DataGridView 来显示用户选择的单元格所在的行和列中的 HeaderText。但到目前为止,我只能获取所选单元格内的值。我知道这在 C# 中更容易做到,但它是一个 C++ 练习。

到目前为止我所拥有的:

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

CurrentRow 和 CurrentCellAddress 似乎对此不起作用,但我可能试图错误地使用它们。

非常感谢所有的建议和见解。

**EDIT**

private: System::Void addAsDestinationCellToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {

    if(DGV->CurrentCell != nullptr)
    {
        String^ c = DGV->Columns[DGV->CurrentCell->ColumnIndex]->HeaderText;
        String^ r = DGV->Rows[DGV->CurrentCell->RowIndex]->HeaderCell->Value->ToString();
        dText->Text = c;
        dText->Text += r;
    }
         }
4

1 回答 1

0

您需要做的是获取当前单元格的列索引值,并使用它来获取HeaderTextDataGridView 中该列的索引值。

这是代码:

String^ t = DGV->Columns[DGV->CurrentCell->ColumnIndex]->HeaderText;
于 2011-03-07T23:27:55.550 回答