我正在使用 C++/CLI Windows 窗体应用程序。
我有一个 DVG,我想通过单击 DVG 的空白区域来取消选择行。我尝试了几种方法,但都没有奏效。1)
System::Void Form1::dataGridView1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
if (e->Button == System::Windows::Forms::MouseButtons::Left)
{
if (dataGridView1->HitTest(e->X, e->Y)->Equals(DataGrid::HitTestInfo::Nowhere))
{
dataGridView1->ClearSelection();
}
}
}
2)这个变体导致错误(错误1错误C3063:运算符'==':所有操作数必须具有相同的枚举类型))
if (e->Button == System::Windows::Forms::MouseButtons::Left)
{
if ((dataGridView1->HitTest(e->X, e->Y)->Type) == DataGrid::HitTestType::None)
{
dataGridView1->ClearSelection();
}
}