开发者

Automatic combo box in datagridview in .net

开发者 https://www.devze.com 2022-12-11 12:31 出处:网络
dim dt as new datatable 开发者_如何学编程 dt.columns.Add(\"Check\", Type.GetType(\"System.Boolean\"))

dim dt as new datatable

开发者_如何学编程 dt.columns.Add("Check", Type.GetType("System.Boolean"))

datagridview1.datasource = dt

A boolean type datacolumn a datatable, when bound to a datagridview automatically shows as DataGridViewCheckBoxColumn. With no code hassles

Inclusion of what type of datacolumn in the datatable will populate a DataGridViewComboBoxColumn similarly.

Any clues


This isn't something a datacolumn type could really do automatically - a dropdown can be bound to different field types and display different field types. While you may see an ID column that links to another table - all it sees is the ID. If you want a dropdown in your datagridview, you're going to have to dispense with the automatic route and start writing the code to bind the dropdown value to one field in one table while telling it to display values from another, or use the designer.


If you use the designer there is a choice when (before) dragging it from the DataSources window, or in the Colums designer.

And in code you can of course use:

    var c = new DataGridViewComboBoxColumn();
    dataGridView1.Columns.Add(c);
0

精彩评论

暂无评论...
验证码 换一张
取 消