传递数据表但没有显示任何结果 [英] passing data table but not showing any result

查看:130
本文介绍了传递数据表但没有显示任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将值传递给另一种形式,但Gridview没有显示任何数据

I am passing value to another form but Gridview not showing any data

dtSearched = objSearching.HadithSearching();
//FrmMain is object of my Frist Form
            FrmMain.dgvAllHadithSearched.DataSource = dtSearched;
            dgvSearchHadith.DataSource = dtSearched;

推荐答案

这是一个糟糕的主意,即使它确实适合你。问题是,通过使表单控件 public ,您锁定表单的设计,并将两个表单绑定在一起,以便在不考虑它们的情况下不能更改它们对另一方的影响。将控件保持为私有(默认情况下)是一个更好的主意,并且只允许通过属性进行访问:在这种情况下,上面代码执行的形式的公共DataTable属性。然后,您发出事件信号,主窗体处理它,导致它在需要时获取数据。



见这里:在两种形式之间转移信息,第2部分:儿童到父母 [ ^ ] - 父母是主要形式,孩子是teh一个提供DataTable。
That's a poor idea, even if it did work for you. The problem is that by making your form controls public you "lock" the design of the form, and tie the two forms together so that they can't be changed without considering the effects on the other. It is a much, much better idea to keep the controls private (as they are by default) and only allow access via properties: in this case a public DataTable property in the form the above code is executing in. You then signal an event, which the main form handles, causing it to fetch the data if it needs it.

See here: Transferring information between two forms, Part 2: Child to Parent[^] - the parent is the main form, the child is teh one providing the DataTable.


这篇关于传递数据表但没有显示任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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