最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

C# crifan 6047浏览 0评论

【背景】

已经在一个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.

转载请注明:在路上 » 【整理】如何使用C#中的DataGridView控件

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.167 seconds, using 22.10MB memory