WinForms C# - Display DataGridView
本文关键字:DataGridView Display WinForms | 更新日期: 2023-09-27 18:06:42
我开发了一个WinForms应用程序,我想通过DataGridView
显示数据。但是,DataGridView
不显示
我决定使用Visible
属性而不是使用多个窗体(当我发现"Tabless TabControl"技巧时已经太晚了,因为我已经在面板中创建了控件)
场景如下:
默认情况下,我的所有控件都是Visible (=true)
。当我启动应用程序时,显示主面板。然后点击搜索按钮,主面板通过设置其Visible
属性为false
隐藏,搜索面板通过设置其Visible
属性为true
显示。
这是功能齐全的:我的搜索面板显示(由于不同的背景颜色测试),但我的DataGridView
里面没有显示。
代码如下:
private void iSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (_mySqlCeEngine.DatabaseExists())
{
dgv_customer.DataSource = _mySqlCeEngine.GetCustomers();
ShowSearchCustomerPanel();
}
}
如果本地数据库文件存在,我给DataTable
充满数据的DataGridView
通过GetCustomers()
方法,然后显示我的搜索面板:
private void ShowSearchCustomerPanel()
{
pnl_home.Visible = false;
pnl_searchCustomer.Visible = true;
}
我拼命地尝试使用Application.DoEvents()
和/或dgv_customer.Refresh()
或再次重新创建DataGridView
,但没有什么是正确的。
谢谢,如果有英文错误,我很抱歉。
悍妇。
如果更改Visible
属性值,DataGridView
类中会出现一个错误。
解决这个bug的方法是:
- 将
DataGridView
从其父Controls.Remove()
中移除以隐藏它; - 将其读取到父
Controls
以再次显示。