即使存在有效数据源,Datagridview 行计数也显示为 0 [英] Datagridview rowcount showing 0 even when there is a valid datasource

查看:20
本文介绍了即使存在有效数据源,Datagridview 行计数也显示为 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态创建的 DataGridView,它有一个有效的 DataSource,其中有一行绑定到它.但是,当我在 DataGridView 上进行行计数时,它返回 0.

I have a dynamically created DataGridView that has a valid DataSource with one row bound to it. However, it is returning me 0 when I am doing a rowcount on the DataGridView.

dgResult.DataSource = resultDt; // a datatable containing one row
flowLayoutPanel.Controls.Add(dgResult); 
int rows = dgResult.Rows.Count; // returning 0 always!

有人可以告诉我这里哪里出错了吗?

Can someone please tell me where I may be going wrong here?

推荐答案

我发现了这个问题.我在未选择的选项卡式页面中显示网格.除非网格可见,否则它不会引发 rowAdded 事件(这很奇怪!) durnig 数据绑定.我在进行数据绑定之前选择了标签页,并且行数起作用了.

I found the issue. I was displaying the grid in a tabbed page that was not selected. Unless the grid is visible, it does not raise the rowadded event (which is weird!) durnig databinding. I selected the tab page before doing the databind, and the rowcount worked.

这篇关于即使存在有效数据源,Datagridview 行计数也显示为 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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