0

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?

Roxy'Pro
  • 4,216
  • 9
  • 40
  • 102
  • You could handle the [RepositoryItemLookupEdit.EditValueChanging](https://documentation.devexpress.com/#WindowsForms/DevExpressXtraEditorsRepositoryRepositoryItem_EditValueChangingtopic) event and set the value of your other column there. – Alex B. May 28 '17 at 18:26
  • @AlexB. Can you please provide simple example of how that might look, I tried to write event handler but unfortunatelly I couldn't. – Roxy'Pro May 28 '17 at 18:48
  • Is the column with `N` or `D` bound or unbound? – Alex B. May 28 '17 at 19:21

1 Answers1

1

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)

Alex B.
  • 2,145
  • 1
  • 16
  • 24
  • I need to change value from "N" to "D" if something is choosen from RepositoryItemLookup/dropdown, so could I somehow check is anything choosen from dropdown, so if yes then change value of my column from N->D ? Which condition I could use instead of e.NewValue = 1? And THANKS FOR YOUR HELP – Roxy'Pro May 28 '17 at 20:43
  • check for edit mate (I dont know why is that sufix "D" there), for every single e.NewValue there is id number + D at the end I really don't know why is that? and one more time thanks a lot this seems to be a solution ! – Roxy'Pro May 28 '17 at 21:02
  • and .newValue is acctually Representing my ID because I said riLookup.ValueMember = "ID? – Roxy'Pro May 28 '17 at 21:30
  • 1. The `D` in the debugger is just an indicator that the number is of type `Decimal` 2. Yes, the `e.NewValue` represents the `ValueMember` of your `DataSource`. I assumed that ID is a number, if it is a string you have to check for `e.NewValue <> string.empty` – Alex B. May 29 '17 at 06:38