Winforms c++;如何防止加载时调用函数inventoryGrid\u CellValueChanged

Winforms c++;如何防止加载时调用函数inventoryGrid\u CellValueChanged,winforms,datagridview,c++-cli,Winforms,Datagridview,C++ Cli,调用LoadItems()函数时,也会触发下面的事件 void InventoryList::LoadItems() { string s = "select * from pos_db.items;"; String^ cmdString = gcnew String(s.c_str()); String^ conString = L"datasource=localhost;port=3306;username=root;password=root"; My

调用LoadItems()函数时,也会触发下面的事件

void InventoryList::LoadItems()
{
    string s = "select * from pos_db.items;";
    String^ cmdString = gcnew String(s.c_str());

    String^ conString = L"datasource=localhost;port=3306;username=root;password=root";
    MySqlConnection^ conDataBase = gcnew MySqlConnection(conString);
    MySqlCommand^ cmdDataBase = gcnew MySqlCommand(cmdString, conDataBase);
    MySqlDataReader^ myReader;

    try
    {
        conDataBase->Open();
        myReader = cmdDataBase->ExecuteReader();
        while(myReader->Read())
        {
            inventoryGrid->Rows->Add();
            DataGridViewRow^ row = inventoryGrid->Rows[inventoryGrid->RowCount - 1];
            row->Cells["alu"]->Value = myReader->GetString(0);
            row->Cells["upc"]->Value = myReader->GetString(1);
            row->Cells["vendor"]->Value = myReader->GetString(2);
            row->Cells["sku"]->Value = myReader->GetString(3);
            row->Cells["description"]->Value = myReader->GetString(4);
            row->Cells["size"]->Value = myReader->GetString(5);
            row->Cells["color"]->Value = myReader->GetString(6);
            row->Cells["price"]->Value = myReader->GetString(7);
            row->Cells["cost"]->Value = myReader->GetString(8);
            row->Cells["quantity"]->Value = myReader->GetString(9);
        }
        conDataBase->Close();
    }
    catch (Exception^ ex)
    {
        MessageBox::Show(ex->Message);
    }
}

private: System::Void inventoryGrid_CellValueChanged(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^  e)
{
    if (inventoryGrid->Visible)
    {
        UpdateItem(e->RowIndex, inventoryGrid->Columns[e->ColumnIndex]->Name, (String^)inventoryGrid->Rows[e->RowIndex]->Cells[e->ColumnIndex]->Value);
    }
}

inventoryGrid->Visible使UpdateItem()函数在最初加载时不会被调用,但是当我搜索某个项目时,它会再次调用LoadItems()函数,从而再次触发事件。问题在于,在搜索过程中调用DataGridView时,DataGridView是可见的,并且会调用UpdateItem()函数。如何避免这种情况发生,而不必看到DataGridView快速闪烁?

您尚未显示搜索代码,因此我不确定为什么搜索要求您再次调用LoadItems。另外,您还没有向UpdateItem显示代码,因此我们不知道其中发生了什么


我想增加一个电话号码。执行挂起,然后对网格进行所有修改,然后调用resume

特别是哪个GUI框架?请(快速)适当地标记您的问题,以避免投反对票@πάνταῥεῖ 事件args位于WinForms命名空间中。@DavidYaw在这个问题上有很多改进……搜索代码的逻辑没有添加任何有帮助的内容。基本上,它只调用LoadItems()函数。不过我还是要试一试。