【整理】如何使用C#中的DataGridView控件

【背景】

已经在一个C#项目中,拖动了一个DataGridView控件到当前窗体中了:

has draged datagridview

接下来,就是搞懂如何使用了。

1.先是:

【已解决】C#中的DataGridView控件使用出错:No row can be added to a DataGridView control that does not have columns

2.后来就可以正常显示数据了:

can list all header and added rows

相关代码:

            //DataGridView init
            dgvSearchResult.ColumnCount = 13;

            //dgvSearchResult.Rows.Add();

            //(1)title
            dgvSearchResult.Columns[0].HeaderText = "Title";
            //(2)seller rating ( based on 1-100% format )
            dgvSearchResult.Columns[1].HeaderText = "Seller Rating";
            //(3)estimated delivery ( based on 24 hours - 7days format )
            dgvSearchResult.Columns[2].HeaderText = "Estimated Delivery";
            //(4)gig rating ( based on 1-100% )
            dgvSearchResult.Columns[3].HeaderText = "Gig Rating";
            //(5)orders in que ( based on 0-9999 format )
            dgvSearchResult.Columns[4].HeaderText = "Orders in Queue";
            //(6)level of the seller ( 1-3 )
            dgvSearchResult.Columns[5].HeaderText = "Seller Level";
            //(7)haz video ( yes or no )
            dgvSearchResult.Columns[6].HeaderText = "Has Video";
            //(8)express gigs (yes or no )
            dgvSearchResult.Columns[7].HeaderText = "Is Express Gig";
            //(9)country flag ( display county flag )
            dgvSearchResult.Columns[8].HeaderText = "Country Flag";
            //(10)+ve reviews and -ve reviews ( based on 1-9999 )
            dgvSearchResult.Columns[9].HeaderText = "Positive Reviews";
            dgvSearchResult.Columns[10].HeaderText = "Negative Reviews";
            //(11)top rated seller ( yes or no )
            dgvSearchResult.Columns[11].HeaderText = "Is Top Rated Seller";
            //(12)gig url
            dgvSearchResult.Columns[12].HeaderText = "Gig Url";

    dgvSearchResult.Rows.Add(
        singleGigInfo.title,
        singleGigInfo.sellerRating,
        singleGigInfo.estimatedDelivery,
        singleGigInfo.gigRating,
        singleGigInfo.ordersInQueue,
        singleGigInfo.sellerLevel,
        singleGigInfo.hasVideo,
        singleGigInfo.isExpressGig,
        singleGigInfo.coutryFlag,
        singleGigInfo.positiveReviews,
        singleGigInfo.negativeReviews,
        singleGigInfo.isTopRatedSeller,
        singleGigInfo.gigUrl);

 

3. 【已解决】C#的DataGridView中,如何选中新添加的行

4. 【已解决】C#的DataGridView中自动在行首添加行号

5. 【已解决】设置C#的DataGridView中的行首的对齐方式

6.



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量