为什么将数据源显示为null? {++公开讨论++} [英] Why it show the datasource as null? {++Open for Discussion++}

查看:115
本文介绍了为什么将数据源显示为null? {++公开讨论++}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我已经编写了一个测试应用程序来测试发票系统的收据打印.如图所示,它首先会加载一个空的gatagridview:

I have written a test application to test receipt printing of a Invoice system. as seen in pictures it loads an empty gatagridview at first:

 

 然后,操作员将一项又一项地添加到购物车中:

 Then the operator adds item by item to the cart: 

 

 当我点击print Recept时,它会抛出错误,因为datagrid没有数据源.

 When i hit print Recept it throws error as the there is no datasource for the datagrid 

 

从事件PrintPage()事件调用了DrawGridBody():

The DrawGridBody() was called from the event PrintPage() event:

 private void prntDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)



 {



 // custom draws the grid from the data



 int columnPosition = 0;



 int rowPosition = 25;







 // draw headers



 DrawHeader(new Font(this.Font, FontStyle.Bold), e.Graphics, ref columnPosition, ref rowPosition);







 rowPosition += 65;







 // draw each row



 DrawGridBody(e.Graphics, ref columnPosition, ref rowPosition);







 }



推荐答案

数据网格视图确实存在.这是数据源,它为空!这意味着您尚未将数据源设置/绑定到有效数据表.您可以使用DataGridView的DataSource属性轻松地做到这一点.
The data grid view does exist. It is the DataSource which is null! It means you have not set / bound the DataSource to a valid data table. You can easily do this using the DataSource property of the DataGridView.


这篇关于为什么将数据源显示为null? {++公开讨论++}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆