如何填充datagrid [英] How to fill datagrid

查看:69
本文介绍了如何填充datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#

推荐答案

private void FillGrid()
       {
           // Set the start and max records.
           pageSize = 3;
           maxRec = dtSource.Rows.Count;
           PageCount = maxRec / pageSize;
           //  Adjust the page number if the last page contains a partial page.

           if (((maxRec % pageSize) > 0))
           {
               PageCount = (PageCount + 1);
           }
           // Initial seeings
           currentPage = 1;
           recNo = 0;
           //  Display the content of the current page.
           LoadPage();
       }

        private void LoadPage()
        {
            int i;
            int startRec;
            int endRec;
            DataTable dtTemp;
            // Duplicate or clone the source table to create the temporary table.
            dtTemp = dtSource.Clone();
            if ((currentPage == PageCount))
            {
                endRec = maxRec;
            }
            else
            {
                endRec = (pageSize * currentPage);
            }
            startRec = recNo;
            if ((dtSource.Rows.Count > 0))
            {
                // Copy the rows from the source table to fill the temporary table.
                for (i = startRec; (i <= (endRec - 1)); i++)
                {
                    dtTemp.ImportRow(dtSource.Rows[i]);
                    recNo = (recNo + 1);
                }
            }
            dataGridView1.DataSource = dtTemp;
            //DisplayPageInfo();
        }


有两种方式: -

1)通过循环

2)通过设置数据源



您想要哪一个?
there are 2 ways :-
1) By Looping
2) By Setting Datasource

which one do you want?


这篇关于如何填充datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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