Search code examples
vb.netwinformsdevexpressdevexpress-windows-ui

How can I change value in another column based on some other column (v.b dev express)


I am using Grid from devExpress to display some data from database, I also implemented RepositoryItemLookUp because I needed to see some values in my column as dropdowns and here is the code:

`Dim riLookup As New RepositoryItemLookUpEdit()

riLookup.NullText = String.Empty

DataTableDobTableAdapter.FillDob(Me.DsOrders.DataTableDob)

riLookup.DataSource = Me.DsOrders.DataTableDob

riLookup.ValueMember = "ID"
riLookup.DisplayMember = "TITLE"
riLookup.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup

GridView1.Columns("Code").ColumnEdit = riLookup`

Here is the photo of that what I am talking about:enter image description here

I'm wondering how can I handle this repositoryitemlookupedit so if whatever is choosen there I might change value of another column from N to D as I highlighted in a image.

Maybe I can write condition in my appereance-> format condition section.

Whatever I need to change another columns value if something is choosen from this repositoryitemlookupedit, whatever I'm really struggling with this because I've never used before v.b neither devexpress.

Thanks guys Cheers!

AFTER ALEX HELP: enter image description here

I put a breakpoint there to check what is e.NewValue and I saw it is acctually ID from database, because I choosed MCI which has ID 1000097 and when breakpoing hitted I catch that Id but with suffix :"D" at the end.. why is that?


Solution

  • You could handle the RepositoryItemLookupEdit.EditValueChanging event.

    Just add an event handler to your existing code:

        Dim riLookup As New RepositoryItemLookUpEdit()
    
        riLookup.NullText = String.Empty
    
        DataTableDobTableAdapter.FillDob(Me.DsOrders.DataTableDob)
    
        riLookup.DataSource = Me.DsOrders.DataTableDob
    
        riLookup.ValueMember = "ID"
        riLookup.DisplayMember = "TITLE"
        riLookup.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup
    
        GridView1.Columns("Code").ColumnEdit = riLookup
       'Add this line:
        AddHandler riLookup.EditValueChanging, AddressOf repItem_EditValueChanging
    

    Now just handle the event and do your logic to set the "N/D" column:

       Private Sub repItem_EditValueChanging(sender As Object, e As ChangingEventArgs)
            If e.NewValue > -1 Then 'any ID given => "N"
                GridView1.SetRowCellValue(GridView1.FocusedRowHandle, GridView1.Columns(6), "D")
            Else
                GridView1.SetRowCellValue(GridView1.FocusedRowHandle, GridView1.Columns(6), "N")
            End If
        End Sub
    

    (I assumed column 6 from your screenshot).

    P.S.: One thing that I couldn´t find in your code but which is neccessary to get a repository item to work properly is to add it to your GridView RepositoryItems collection like:

    GridControl1.RepositoryItems.Add(riLookup)