码迷,mamicode.com
首页 > 其他好文 > 详细

DateGridView中添加下拉框列并实现数据绑定

时间:2016-08-23 15:02:01      阅读:479      评论:0      收藏:0      [点我收藏+]

标签:

代码实现==》
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace DgvCombox
{
    public partial class Form1 : Form
    {
        class TextInfo
        {
            public string MyName { get; set; }
            public string Sex { get; set; }
        }

        public Form1()
        {
            InitializeComponent();
            this.dgvList.AutoGenerateColumns = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<string> sexList = new List<string>();
            sexList.Add("男");
            sexList.Add("女");
            List<TextInfo> list = new List<TextInfo>();
            list.Add(new TextInfo { MyName = "001", Sex = "男" });
            list.Add(new TextInfo { MyName = "002", Sex = "女" });
            list.Add(new TextInfo { MyName = "003", Sex = "女" });
            list.Add(new TextInfo { MyName = "004", Sex = "女" });

            //this.dgvList.DataSource = list;

            for (int i = 0; i < list.Count; i++)
            {
                dgvList.Rows.Add();
                this.dgvList.Rows[i].Cells[0].Value = list[i].MyName;
                this.dgvList.Rows[i].Cells[1].Value = list[i].Sex;
            }

            ((DataGridViewComboBoxColumn)this.dgvList.Columns["Sex"]).DataSource = sexList;
            this.dgvList.AllowUserToAddRows = true;
        }
    }
}

  

DateGridView中添加下拉框列并实现数据绑定

标签:

原文地址:http://www.cnblogs.com/YYkun/p/5799084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!