首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Windows应用程序中创建EmptyDataText for DataGridView

如何在Windows应用程序中创建EmptyDataText for DataGridView
EN

Stack Overflow用户
提问于 2011-05-03 07:32:43
回答 2查看 4.5K关注 0票数 6

今天,我面临着根据数据源显示/隐藏标签的问题。如果数据源没有行,那么,我想设置“无数据找到” of,在winforms应用程序中显示记录的数量()。

这在Asp.net中是可能的,比如:

代码语言:javascript
复制
<emptydatatemplate>
No Data Found
</emptydatatemplate>

代码语言:javascript
复制
EmptyDataText=" No Data Found"

但是我想在Windows应用程序中。如果您有相同的解决方案,请帮助我。

任何解决方案都将不胜感激!谢谢你,Imdadhusen

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-04 06:22:09

实现这一目标的一种方法是使用画图()事件来检查行,如果没有行,则编写消息:折叠

代码语言:javascript
复制
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

票数 14
EN

Stack Overflow用户

发布于 2018-02-08 11:26:04

由于我在使用画图事件实现此行为时遇到了问题,因此我在窗体中添加了一个面板,其中包含了我想要显示的图形,如果没有显示任何数据(基本上是几个标签),并在需要时与网格交换。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5866458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档