如何在datagridview中更改列类型 [英] how to change column type in datagridview

查看:355
本文介绍了如何在datagridview中更改列类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有数据库访问权限和c#表单的项目

我想在gridviewworkers的department_ID列中将列类型更改为combobox
gridviewworkers中的
department_id列是外键对于departments表中的department_id列

gridviewworkers与worker表关联



我使用了以下代码,但不知道是什么''错误





DataGridViewComboBoxColumn combo =(DataGridViewComboBoxColumn)this.dataGridworkers.Columns [2];

combo .DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;

combo.DataSource = WorkersMgr.GetAllDepartments();

combo.DisplayMember =Department_Name;

combo .ValueMember =Department_ID;



注意:GetAllDepartments()返回部门表中的所有部门名称

解决方案

< blockquote>在datagrid v iew任务面板单击编辑按钮并将列类型设置为组合框,而代码将执行其余工作..


I have a project with a database access and c# forms
I want to change column type to combobox from department_ID column in gridviewworkers
department_id column in gridviewworkers is foreign key for department_id column in departments table
gridviewworkers is associated with workers table

I used the following code but didn''t know what''s mistake


DataGridViewComboBoxColumn combo = (DataGridViewComboBoxColumn)this.dataGridworkers.Columns[2];
combo.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
combo.DataSource = WorkersMgr.GetAllDepartments();
combo.DisplayMember = "Department_Name";
combo.ValueMember = "Department_ID";

note: GetAllDepartments() returns all departments names from departments table

解决方案

In datagrid view tasks panel click on edit button and set column type to combobox than you code will do the rest work..


这篇关于如何在datagridview中更改列类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆