如何获取cgridctrl中的项目数? [英] How to get number of items in cgridctrl?

查看:85
本文介绍了如何获取cgridctrl中的项目数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在CGridCtrl中,我最初在SetRowCount()中设置了16。

点击添加按钮时我动态填充行。

现在我在CGridctrl中只填充了3行。

OnOK()我需要在CGridCtrl中获取已填充的行数。

在cListctrl的MFC中我们有GetItemCount ()函数来获取填充项目数。同样在CGridCtrl中如何获得填充行的数量?



我尝试了什么:



我探索但找不到它的功能。

Hi,
In CGridCtrl I initially set 16 in SetRowCount().
I am dynamically filling the row when clicking add button.
Now I have filled only 3 rows in the CGridctrl.
OnOK() I need to get number of filled rows in the CGridCtrl.
In MFC in cListctrl we have GetItemCount() function to get filled items count. likewise in CGridCtrl how to get number of filled row?

What I have tried:

I explored but couldn't find function for it.

推荐答案

你应该在文章末尾的论坛中发表你的问题,以便作者看到它。
You should post your question in the forum at the end of the article so the author sees it.


使用类成员变量设置数据时,可以在代码中跟踪它。



或者你可以查看如果特定列不为空(这需要知道列的类型,并且在使用虚拟模式时设置这些列总是不为空)。



未经测试的示例:

You can track it in your code when setting data using a class member variable.

Or you can check if specifc column(s) are not empty (which requires knowing the type of the columns and that these columns are always not empty once set when using virtual mode).

Untested example:
int CMyClass::GetUsedRows() const
{
    int usedRows = 0;
    for (int i = 0; i < m_gridCtrl.GetRowCount(), i++)
    {
        const CGridCellBase* pCell = m_gridCtrl.GetCell(i, 0);
        if (pCell)
        {
            // When not using virtual mode, pCell is NULL when no data has been set
            // Otherwise assumes column 0 is text and that it is always a non empty string
            if (!m_gridCtrl.GetVirtualMode() || (pCell->GetText() && *pCell->GetText()))
                usedRows++;
        }
    }
    return usedRows;
}


这篇关于如何获取cgridctrl中的项目数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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