vb.net GridView存储值,但显示来自datatable的文本

时间:2016-09-30 15:13:35

标签: vb.net

我想在gridview或datatable中存储地址的值,但要显示它的名称,所以在将数据保存到数据库时,我会插入值。

    dtCust_dtls.DefaultView.RowFilter = String.Format("SR_ID = '{0}'", SrLookup.GetSelectedItem("SR_ID"))
    GCCustList.DataSource = dtCust_dtls.DefaultView

    GVCustList.Columns("CUSTOMER_CODE").VisibleIndex = 0
    GVCustList.Columns("ADDRESS_ID").VisibleIndex = 1
    GVCustList.Columns("CUSTOMER_CODE").Caption = "Customer Code"
    GVCustList.Columns("ADDRESS_ID").Caption = "Address"

按钮添加

  dtCust_dtls.DefaultView.RowFilter = String.Format("SR_ID = '{0}' and CUSTOMER_CODE = '{1}'", SrLookup.GetSelectedItem("SR_ID"), txtCust_Code.Text.Trim)
    If (dtCust_dtls.DefaultView.Count = 0) Then
        Dim dr As DataRow = dtCust_dtls.NewRow()
        dr("SR_ID") = SrLookup.GetSelectedItem("SR_ID")
        dr("CUSTOMER_ID") = DataRowSelectedCust("CUSTOMER_ID")
        dr("ADDRESS_ID") = cmbCustAdd.SelectedValue
        dr("CUSTOMER_CODE") = txtCust_Code.Text.Trim
        dr("CUSTOMER_BARCODE") = DataRowSelectedCust("CUSTOMER_ID") & "." & cmbCustAdd.SelectedValue 'custId + . + addID
        dr("STAMP_DATE") = Now
        dtCust_dtls.Rows.Add(dr)
    Else
        MsgBox("The Customer code '" & txtCust_Code.Text & "' already exist for " & txtSrName.Text)
    End If

enter image description here

on save btn我正在保存数据表dtCust_dtls。

我有一个想法是添加一列:地址名称并保留列地址ID,但我不知道该怎么做!

1 个答案:

答案 0 :(得分:0)

使用RepositoryItemLookUpEdit

 Dim xCust_Code As New DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit
    With xCust_Code
        .ForceInitialize()
        .DataSource = dtCustList.DefaultView
        .DisplayMember = "Customer_Description"
        .ValueMember = "Customer_Code"
        .PopulateColumns()
        .NullText = String.Empty
    End With
    GVCustDUE.Columns("CUSTOMER_CODE").ColumnEdit = xCust_Code