2011-05-03 58 views
3

今天我面臨根據數據源顯示/隱藏標籤的問題。如果數據源沒有行然後我想設置「沒有數據發現」其他顯示記錄數在winforms應用程序如何在Windows應用程序中爲DataGridView創建EmptyDataText

這將有可能在Asp.net,如:

<emptydatatemplate> 
No Data Found 
</emptydatatemplate> 

OR

EmptyDataText=" No Data Found" 

但我想在Windows應用程序。如果你有相同的解決方案,請幫助我。

任何解決方案,將不勝感激! 謝謝, Imdadhusen

你能做到這一點

回答

10

一種方法是使用塗料()事件來檢查行,如果沒有,那麼你的留言: 收起

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

0

由於我在實施使用Paint事件這種行爲的麻煩,我加入一個小組,我的形式包含我希望當沒有顯示數據來顯示圖形(基本上解決幾個標籤),並在需要時與網格交換。

相關問題