在 DevExpress vb.net 中使用 CheckBoxList 分配和评估?
Use CheckBoxList in DevExpress vb.net Assign & Evaluate?
你好,我的代码示例是:
/*
bdCompany(绑定源)
包含:
选择 idCompany、名称、从公司访问
结果
1,Company1,真
2, Company2,false
3, Company2,true
*/
clEmpresas.DataSource = bdCompany
clEmpresas.DisplayMember = ? (姓名)
clEmpresas.ValueMember = ? (访问)
这是我们要使用的代码
With clEmpresas.Properties
If .DataSource IsNot Nothing Then .DataSource = Nothing
.DataSource = bdEmpresa
If .DataSource.rows.count = 0 Then Return Nothing 'no data to load
'get the names from the dataset, don't expect them to be specific names
.ValueMember = .DataSource.rows(0).Table.Columns(0).ColumnName
.DisplayMember = .DataSource.rows(0).Table.Columns(1).ColumnName
'Set the selected items, comma separated list of ids
If selectedIds <> "" Then
For i As Integer = 0 To .ItemCount - 1
If Array.IndexOf(selectedIds.Split(","), .GetItemValue(i).ToString) >= 0 Then
.SetItemChecked(i, True)
End If
Next
End If
End With
您可以使用 CheckMember 属性 让控件自动检查您分配的数据源中的选择值:
例如
clEmpresas.DataSource = bdEmpresa
clEmpresas.DisplayMember = "Nombre"
clEmpresas.ValueMember = "idEmpresa"
clEmpresas.CheckMember= "Acceso"
之后,如果用户在控件中更改选择,您可以使用 CheckedItems 属性 获取所选项目。请参阅以下示例:
Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
For Each item As DevExpress.XtraEditors.Controls.CheckedListBoxItem In CheckedListBoxControl1.CheckedItems
MessageBox.Show(item.Value.ToString())
Next
End Sub
参考这些:
get the selected items from a checkedlistbox
How to get checked rows of a data-bound CheckedListBoxControl
Get item index from databound DevExpress CheckedListBoxControl
你好,我的代码示例是:
/* bdCompany(绑定源) 包含:
选择 idCompany、名称、从公司访问
结果
1,Company1,真
2, Company2,false
3, Company2,true
*/
clEmpresas.DataSource = bdCompany
clEmpresas.DisplayMember = ? (姓名)
clEmpresas.ValueMember = ? (访问)
这是我们要使用的代码
With clEmpresas.Properties
If .DataSource IsNot Nothing Then .DataSource = Nothing
.DataSource = bdEmpresa
If .DataSource.rows.count = 0 Then Return Nothing 'no data to load
'get the names from the dataset, don't expect them to be specific names
.ValueMember = .DataSource.rows(0).Table.Columns(0).ColumnName
.DisplayMember = .DataSource.rows(0).Table.Columns(1).ColumnName
'Set the selected items, comma separated list of ids
If selectedIds <> "" Then
For i As Integer = 0 To .ItemCount - 1
If Array.IndexOf(selectedIds.Split(","), .GetItemValue(i).ToString) >= 0 Then
.SetItemChecked(i, True)
End If
Next
End If
End With
您可以使用 CheckMember 属性 让控件自动检查您分配的数据源中的选择值: 例如
clEmpresas.DataSource = bdEmpresa
clEmpresas.DisplayMember = "Nombre"
clEmpresas.ValueMember = "idEmpresa"
clEmpresas.CheckMember= "Acceso"
之后,如果用户在控件中更改选择,您可以使用 CheckedItems 属性 获取所选项目。请参阅以下示例:
Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
For Each item As DevExpress.XtraEditors.Controls.CheckedListBoxItem In CheckedListBoxControl1.CheckedItems
MessageBox.Show(item.Value.ToString())
Next
End Sub
参考这些:
get the selected items from a checkedlistbox
How to get checked rows of a data-bound CheckedListBoxControl
Get item index from databound DevExpress CheckedListBoxControl