今天,我面临着根据数据源显示/隐藏标签的问题。如果数据源没有行,那么,我想设置“无数据找到” of,在winforms应用程序中显示记录的数量()。
这在Asp.net中是可能的,比如:
<emptydatatemplate>
No Data Found
</emptydatatemplate>或
EmptyDataText=" No Data Found"但是我想在Windows应用程序中。如果您有相同的解决方案,请帮助我。
任何解决方案都将不胜感激!谢谢你,Imdadhusen
发布于 2011-05-04 06:22:09
实现这一目标的一种方法是使用画图()事件来检查行,如果没有行,则编写消息:折叠
private void dataGridView1_Paint ( object sender, PaintEventArgs e )
{
DataGridView sndr = ( DataGridView )sender;
if ( sndr.Rows.Count == 0 ) // <-- if there are no rows in the DataGridView when it paints, then it will create your message
{
using ( Graphics grfx = e.Graphics )
{
// create a white rectangle so text will be easily readable
grfx.FillRectangle ( Brushes.White, new Rectangle ( new Point (), new Size ( sndr.Width, 25 ) ) );
// write text on top of the white rectangle just created
grfx.DrawString ( "No data returned", new Font ( "Arial", 12 ), Brushes.Black, new PointF ( 3, 3 ) );
}
}
}感谢JOAT-MON接受的解决方案。
谢谢你,Imdadhusen
发布于 2018-02-08 11:26:04
由于我在使用画图事件实现此行为时遇到了问题,因此我在窗体中添加了一个面板,其中包含了我想要显示的图形,如果没有显示任何数据(基本上是几个标签),并在需要时与网格交换。
https://stackoverflow.com/questions/5866458
复制相似问题