2017-07-18 53 views
0

你好我的代碼示例:在DevExpress vb.net中使用CheckBoxList分配&評估?

/* bdEmpresa(的BindingSource) 包含:

selet idEmpresa,農佈雷,Acceso從Empresa與

結果

1,Empresa1,真正

2,Empresa2,false

3,Empresa2,真

*/

clEmpresas.DataSource = bdEmpresa

clEmpresas.DisplayMember =? (Nombre)

clEmpresas.ValueMember =? (Acceso)

回答

0

這是代碼,我們將使用

 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 
0

可以使用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