如何访问已处置的对象?

时间:2015-03-23 23:50:09

标签: c++-cli windows-forms-designer

  

这是我展示表格的地方。基本上我正在编辑数据库中的数据。我在DataGridViewRow对象的行中得到了异常。

private: System::Void button2_Click(System::Object^  sender,  System::EventArgs^  e) 
{
    int selectedIndex = dataGridView1->CurrentCell->RowIndex;

    if (selectedIndex >= 0)
    {
        MessageBox::Show("selection is" + selectedIndex);
        edit->Show();

        try
        {
            DataGridViewRow ^row = this->dataGridView1->Rows[selectedIndex];

            edit->itemcodetextBox->Text = row->Cells[0]->Value->ToString();
            edit->itemnametextbox->Text = row->Cells[1]->Value->ToString();
            edit->stockamnttextBox->Text = row->Cells[2]->Value->ToString();
            edit->pricetextBox->Text = row->Cells[3]->Value->ToString();
            edit->categorytextBox->Text = row->Cells[4]->Value->ToString();         
        }
        catch (Exception^ ex)
        {
            MessageBox::Show(" Error Updating Data ");
        }           
    }

0 个答案:

没有答案