DataGridView RowCount 与 Rows.Count [英] DataGridView RowCount vs Rows.Count

查看:38
本文介绍了DataGridView RowCount 与 Rows.Count的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个 DataGridView uxChargeBackDataGridView.

If I have a DataGridView uxChargeBackDataGridView.

以下是否在句法上不同但实际上相同?:

Are the following syntactically different but effectively the same?:

int numRows = uxChargeBackDataGridView.Rows.Count;
int numRowCount = uxChargeBackDataGridView.RowCount;

如果 uxChargeBackDataGridView 为空,则两者都等于 1;因此从逻辑上讲,如果其中任何一个等于 1,我就可以假设用户没有输入任何数据吗?

If uxChargeBackDataGridView is empty then both are equal to 1; does it therefore logically stand that if either of these is equal to 1 I can assume the user has not input any data?

WinFroms 有一个按钮 RUN - 我可以使用上面的测试来决定是否启用此按钮,即仅在 行数 > 1 时启用该按钮 ?

The WinFroms has a button RUN - could I use the above test to decide if this button is enabled or not i.e only enable the button when the number of rows is >1 ?

推荐答案

两种说法都是一样的.但是,要记住的一件事是,仅当 AllowUsersToAddRow 属性设置为 true 时,空"数据网格视图才有 1 条记录.否则,行数将为 0.

Both statements are the same. However, one thing to remember is that an "empty" datagridview has 1 record only if the AllowUsersToAddRow property is set to true. Otherwise, the row count will be 0.

我想补充一点,代替 MMK 的回答,如果您不手动或以编程方式更改 RowCount,它们将返回相同的值.请参阅 http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowcount.aspx.

I would like to add, in lieu of MMK's answer that if you do not change the RowCount, either manually or programatically, they will return the same value. See http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowcount.aspx.

这篇关于DataGridView RowCount 与 Rows.Count的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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