如何将repositorylookup编辑中的值设置为gridview中的特定列

时间:2017-05-12 04:32:35

标签: c# winforms devexpress

当我选择产品时,如何将值设置为gridview列price? 所以我不需要手动输入。

enter image description here

Dim repo_lookupedit_gv2 As New Repository.RepositoryItemLookUpEdit

  Public Sub load_product()
    Dim perintah As New SqlCommand
    Dim dt As New DataTable
    Try
        Using MyAdapter As New SqlDataAdapter
            knk.MyConnection.Open()
            dt.Clear()
            With perintah
                .Connection = knk.MyConnection
                .CommandText = "select * from product"
                MyAdapter.SelectCommand = perintah
                MyAdapter.Fill(dt)
            End With
        End Using                    

        repo_lookupedit_gv2.DataSource = dt
        repo_lookupedit_gv2.ValueMember = dt.Columns("code").ToString
        repo_lookupedit_gv2.DisplayMember = dt.Columns("product").ToString
        repo_lookupedit_gv2.PopupWidth = 450

        gridview2.columns("product").columnedit = repo_lookupedit_gv2

        AddHandler repo_lookupedit_gv2.EditValueChanged, AddressOf repo_lookupedit_gv2_changed

    Catch ex As Exception
        MsgBox("Failed to load data product !")
    Finally
        knk.MyConnection.Close()
    End Try
End Sub

Private Sub GridView2_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles GridView2.InitNewRow
    Dim row As DataRow = GridView2.GetDataRow(e.RowHandle)
    row("qty") = 1
    row("price") = repo_lookupedit_gv2.Columns("price").ToString() \\\'it give me error
End Sub

enter image description here

我已经尝试了

    Private Sub repo_lookupedit_gv2_changed(sender As Object, e As EventArgs)
    MsgBox(repo_lookupedit_gv2.Columns("price").ToString())
End Sub

哪不给我任何东西

enter image description here

1 个答案:

答案 0 :(得分:1)

请参阅: GridControl - How to get a value from the in-place GridLookUpEdit editor's column and change a value in another grid column correspondingly

Private Sub repositoryItemGridLookUpEdit1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim editor As GridLookUpEdit = TryCast(sender, GridLookUpEdit)
            Dim index As Integer = editor.Properties.GetIndexByKeyValue(editor.EditValue)
            If index < 0 Then
                Return
            End If

            Dim value As Object = (TryCast(editor.Properties.View.GetRow(index), DataRowView)).Row("Name")
            gridView2.SetFocusedRowCellValue("Name", value)
  End Sub

请参阅上面的示例,您可以获取编辑器Row或Class对象,具体取决于您使用repositoryitem控件绑定的数据源类型。

在您的情况下,您将其与数据表绑定,然后您将获得DataRowView,如图所示。之后,您可以使用方法gridView2.SetFocusedRowCellValue("Name", value)

获取选定的行列值并将其设置为网格行单元格值

参考文献:
How to get and set the GridLookUpEdit's value