简体   繁体   English

在未绑定的Datagridview中将bit Column显示为复选框列

[英]Show bit Column as a checkbox column in unbound Datagridview

Dim Comp = From C In db.Table1 _
Select C.Completed, C.Taken, C.Namne

Datagridview1.DataSource = Comp

Am using the Entity Framework and Columns Completed and Taken are of bit Datatype. 我正在使用Entity Framework,并且Completed和Taken列的数据类型为bit。 When the query results are displayed in the datagridview, these bit columns are returned as of ColumnType Textbox - so i get a Datagridview textbox column with true or false string values. 当查询结果显示在datagridview中时,这些位列从ColumnType Textbox开始返回-因此我得到了具有正确或错误字符串值的Datagridview文本框列。

I want to display Completed and Taken as Checkbox columns (either ticked for True or un-ticked for false) but ofcourse i can't do this in EditColumn dialogue because the Datagridview is unbound. 我想显示CompletedTaken as Checkbox列(勾选为True或取消勾选为false),但是我当然不能在EditColumn对话框中这样做,因为Datagridview是未绑定的。

how can i change this in code at runtime 我如何在运行时在代码中更改

Edit: 编辑:

I just looked at your code again and I realised that what you actually mean is that the DGV is bound rather than unbound? 我只是再次查看了您的代码,才意识到您真正的意思是DGV是绑定的而不是未绑定的? Since you're binding it to Comp . 由于您将其绑定到Comp

If I understand correctly, just create 3 columns in the DGV at design time, 1 DataGridViewTextBoxColumn and 2 DataGridViewCheckBoxColumn . 如果我理解正确,只需在设计时在DGV中创建3列,即1 DataGridViewTextBoxColumn和2 DataGridViewCheckBoxColumn Then set the DataPropertyName of each column (Completed or Taken for the checkbox columns etc). 然后设置每列的DataPropertyName(复选框列已完成或已采用,等等)。

If the DataPropertyNames are correct the data will appear in them (if they're not correct, you'll end up with 6 columns in total). 如果DataPropertyNames正确,则数据将出现在其中(如果它们不正确,则总共将有6列)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM