如何设置comboboxcolumn

如何设置comboboxcolumn

本文介绍了当datagridviews数据源是数据表时,如何设置comboboxcolumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将datagridview绑定到datatable。其中三列应该显示一个组合框。



我没有找到如何将textboxcolum的列类型更改为comboboxcolumn

google hasn'帮助了我。搜索datagridview和comboboxcolumn会带来很多答案,但没有一个能解决我的问题。



我尝试过:



在给定数据表上我做:


I want to bind a datagridview to datatable. three of the columns should display a combobox.

I havn't found how to change column type form textboxcolum to comboboxcolumn
google hasn't helped me. searching datagridview and comboboxcolumn brings a lot of answers but none covers my problem.

What I have tried:

on a given datatable I do :

dgv.datasource = datatable



这将使所有列到textboxcolumn

所以如何在此处继续表单?

任何想法?

提前感谢


that will make all columns to textboxcolumn
so how do I proceed form here on ?
any ideas ?
thanks in advance

推荐答案

public Form1()
{
    InitializeComponent();

    //disable column autogeneration
    dataGridView1.AutoGenerateColumns = false;
    dataGridView1.AutoSize = true;
    //bind sample data
    dataGridView1.DataSource = CustomBindingSource();

    //create columns manually
    //TextBoxColumn
    DataGridViewTextBoxColumn txt = new DataGridViewTextBoxColumn();
    txt.DataPropertyName = "EmpId";
    txt.Name = "EmpId";
    dataGridView1.Columns.Add (txt);

    //ComboBoxColumn
    DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
    combo.DataSource = Enum.GetValues(typeof(Sex));
    combo.DataPropertyName = "Sex";
    combo.Name = "Sex";
    dataGridView1.Columns.Add(combo);

    //that's all!
}





其他有趣的资源:

[]

[]


这篇关于当datagridviews数据源是数据表时,如何设置comboboxcolumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:14