Tony Tony - 2 months ago 10
Vb.net Question

vb.net GridView store value but display text from datatable

Please I want to store the value of address in the gridview or datatable but display it's name, so when saving data to database I will insert the value.

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"


on button add

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 I am saving the datatable dtCust_dtls as it is.

I had an idea to add one column : Address Name and leave the column Address ID but I don't have any idea how to do it !

Answer

USING THE 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