如何使用另一个数据源

时间:2015-11-13 07:48:41

标签: vb.net devexpress

在这里我将解释我想问的问题。 在我解释我的问题之前。

我创建了一个程序并添加了1个表单,在我的表单中添加了组合框,deexpress的组件是GridLookupEdit。

组合框本身的功能,显示选项类别。

Gridlookup 将根据从Combobox中选择的类别显示数据库中的数据。

当时我选择了第一个类别,即“学习计划”。从组合框中,数据在GridLookup中成功执行。

但是当我选择其他类别时,这是基于数据的类别我选择数据库中的现有数据,但它不能显示所有GridLookup。

并且Gridlookup仅列出先前已清空的项目和menyisahkan以前数据的名称列。

我使用的代码和我在下一页上附上截图:

    Private Sub CBCariOpt_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CBCariOpt.SelectedIndexChanged
    With CBCariOpt
        If .SelectedIndex = -1 Or .Text = "" Then Exit Sub
        If .SelectedIndex = 0 Or .SelectedIndex = 1 Or .SelectedIndex = 4 Or .SelectedIndex = 5 Then
           GLOptCari.Properties.DataSource = DBNull.Value
           FilDataBantuGridLookup(.SelectedIndex, GLOptCari, DKritria, General.Constant.ConfigPath)
        Else
           GLOptCari.SendToBack()
           With DKritria
                    .BringToFront()
                    .Text = ""
                    .Focus()
                    .Select()
            End With
        End If
    End With
End Sub

FillData代码到数据源Gridlookup

   Private Sub FilDataBantuGridLookup(SelIndex As Integer, GL As GridLookUpEdit, dkritria As MetroTextBox, path As String)
    With QD
       If SelIndex = 0 Then .FillToGridLook(QProdi, GL, "PRODI", "KODE", path)
       If SelIndex = 1 Then .FillToGridLook(QJursan, GL, "JURUSAN", "KODE", path)
       If SelIndex = 4 Then .FillToGridLook(QThAnktan, GL, "THN_ANGKATAN", "THN_ANGKATAN", path)
       If SelIndex = 5 Then .FillToGridLook(QThWisda, GL, "THN_WISUDA", "THN_WISUDA", path)
       .Dispose()
       GL.Properties.PopupFormSize = New Size With {.Width = GL.Width} 'GridLookUpEdit
       GL.BringToFront()
       dkritria.SendToBack()
    End With
End Sub

在GridLookupEdit中查询数据源:

Public Sub FillToGridLook(ByVal query As String, FilCtl As DevExpress.XtraEditors.GridLookUpEdit, SDis As String, SVal As String, ByVal path As String)
    Using KN As New Koneksi.Koneksi
        If KN.OpenFromFile(path) Then
            Using da As New MySqlDataAdapter(query, KN.OKoneksi)
                Dim dt As New DataTable
                dt = New DataTable
                dt.Rows.Clear()
                dt.Columns.Clear()
                da.Fill(dt)
                If dt.Rows.Count > 0 Then
                    FilCtl.Refresh()
                    FilCtl.RefreshEditValue()
                    With FilCtl.Properties
                        .DataSource = Nothing
                        .DataSource = dt
                        .DisplayMember = SDis
                        .ValueMember = SVal
                        .ImmediatePopup = True
                        .View.OptionsView.ShowColumnHeaders = False
                    End With
                    FilCtl.Refresh()

                End If
                da.Dispose()
                dt.Dispose()
            End Using
        End If
        KN.Dispose()
    End Using
End Sub

结果:

Screen Shoot

因此,我想问一下:

  1. 如何刷新gridlookup中最初必须在新数据之前容纳初始数据的DataSource?

0 个答案:

没有答案