大家好:
    我想在 从数据库中读取数据时   如果没有检索到相关数据  怎样在dataGridView上 提示 没有检索到数据 呢?
                                     谢谢大家了! 

解决方案 »

  1.   

    http://blog.csdn.net/califord/archive/2006/03/03/614439.aspx   
      

  2.   

    判断一下有没数据,然后让GRIDVIEW不显示,一个DIV就显示暂无数据
      

  3.   

    datagridview
    应该也有一个属性: empty显示的吧
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication259
    {
        public partial class Form1 : Form
        {
            DataGridViewEx DGV = new DataGridViewEx();        public Form1()
            {
                InitializeComponent();            DGV.Columns.Add("c1", "c1");
                DGV.Parent = this;
                DGV.Dock = DockStyle.Fill;
                DGV.AllowUserToAddRows = false;            Button B = new Button();
                B.Parent = DGV;
                B.Text = "加载";
                B.Click += new EventHandler(B_Click);
            }        void B_Click(object sender, EventArgs e)
            {
                DGV.Rows.Add();
            }        class DataGridViewEx : DataGridView
            {
                protected override void OnPaint(PaintEventArgs e)
                {
                    base.OnPaint(e);                if (this.RowCount == 0)
                    {
                        String S = "没有检索到数据";
                        SizeF SF = e.Graphics.MeasureString(S, this.Font);                    e.Graphics.DrawString(S, this.Font, Brushes.Silver,
                        (this.ClientRectangle.Width - SF.Width) / 2, (this.ClientRectangle.Height - SF.Height) / 2);
                    }
                }            protected override void OnResize(EventArgs e)
                {
                    base.OnResize(e);
                    this.Invalidate();
                }
            }
        }
    }