0

I try to make grid columns during runtime, and one of column using repositorycheckedit, I tried several methods but none worked

here is my code

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

somehow, the column supposed to show checkbox always grayed out, if i try to mark the checkbox, it will become null after lost focus/change cell

pplease anyone.? thanks

Source #2 (After revised) and still no result as expected

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
Imam
  • 37
  • 6
  • This is likely not related to your issue but what is the `DataSet` for? Just create the `DataTable` and assign that directly to the `DataSource`. I don;t use that particular grid control but you can do it that way with a `DataGridView` so I suspect that this one is the same. Don't create a `DataSet` where a `DataTable` alone will do the job. – jmcilhinney Jun 07 '21 at 05:00
  • Also, your code makes little sense where you create/add the columns to the table. You create a `DataColumn` and set its `ColumnName` and `Caption` but then you never use it. You then add two columns with names but then immediately discard that name and set their `ColumnName` directly. That part is all over the place. Just create the table and then call `Columns.Add` twice, specifying a name and data type. If you want to set the `Caption` too then chain that on the end, e.g. `table.Columns.Add("FullName", GetType(String)).Caption = "Full Name"`. – jmcilhinney Jun 07 '21 at 05:05
  • @jmcilhinney thank you, that is correct, just realized you can just ignore dataset and create table using datatable. Now I revised a little my code, but still the checkedit won't work as expected.. (still grayed out) – Imam Jun 07 '21 at 06:08

1 Answers1

0

After tried several times, maybe someone needs answer So finally I solved it. When create columns we need to define what type for the columns

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

And things finally worked.

Imam
  • 37
  • 6