0

我尝试在运行时制作网格列,其中一个列使用repositorycheckedit,我尝试了几种方法,但都没有奏效

这是我的代码

Dim dtSet As New DataSet()
        Dim dtTable As New DataTable("menu")
        Dim grCol As New DataColumn
        Dim rpChk As New RepositoryItemCheckEdit

        grCol.ColumnName = "smenu"
        grCol.Caption = "Menu"
        dtTable.Columns.Add("Menu")
        dtTable.Columns(0).ColumnName = "smenu"
        dtTable.Columns.Add("New")
        dtTable.Columns(1).ColumnName = "snew"

        dtTable.Rows.Add("Nama", 1)

        dtSet.Tables.Add(dtTable)

        gr.DataSource = dtSet
        gr.DataMember = "menu"

        rpChk.ValueChecked = 1
        rpChk.ValueUnchecked = 0
        grV.Columns("snew").ColumnEdit = rpChk

不知何故,应该显示复选框的列总是变灰,如果我尝试标记复选框,它会在失去焦点/更改单元格后变为空

请任何人.? 谢谢

来源#2(修改后)仍然没有预期的结果

Dim dtTable As New DataTable("menu")
Dim rpChk As New RepositoryItemCheckEdit

dtTable.Columns.Add("Menu")
dtTable.Columns(0).ColumnName = "smenu"
dtTable.Columns.Add("New")
dtTable.Columns(1).ColumnName = "snew"

dtTable.Rows.Add("Nama", CSByte(1))
dtTable.Rows.Add("Nama1", CSByte(0))
dtTable.Rows.Add("Nama2", CSByte(1))
dtTable.Rows.Add("Nama3", CSByte(0))

gr.DataSource = dtTable

rpChk.ValueChecked = 1
rpChk.ValueUnchecked = 0

grV.Columns("snew").ColumnEdit = rpChk
4

1 回答 1

0

经过几次尝试,也许有人需要回答所以最后我解决了。创建列时,我们需要定义列的类型

dtTable.Columns.Add("Menu",GetType(String))
dtTable.Columns(0).ColumnName = "smenu"
dtTable.Columns.Add("New",GetType(Boolean))
dtTable.Columns(1).ColumnName = "snew"

事情终于奏效了。

于 2021-06-08T15:43:57.860 回答