Reputation: 1223
I want to do the following: I have an XtraGrid (short Grid) on top of an Dialog to choose e.g. offers. A offer has a dealer from a list of all dealers. 'offer' and 'dealer' are XPO Objects. In the lower part there is a GridLookUpEdit (short LookUp)
Maybe I'm totally in a wrong way, because we used another data mapper before, but I'm completly stuck.
I have defined an XPCollection which is bound to the Grid and another XPCollection bound to the LookUp.
If I select a row in the Grid, values of Lookups which are not XPO-objects get changed according to the selected row. As soon as the LookUp contains an XPO Object nothing is displayed. Session of all XPCollections are the same.
If i click in the LookUp, a list of all Dealers is shown.
If i select an entry I do the following:
Order order = gridView.GetRow(gridView.FocusedRowHandle); => shows an order
Dealer actDealer = this.gridLookUpEditDealer.EditValue as Dealer; => shows a Dealer
order.Dealer = actDealer; => lets the selected value vanish.
this.gridLookUpEditDealer.EditValue stays the same, but is no longer displayed.
The DataBinging of the LookUp is:
this.gridLookUpEditDealer.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.mainGrid, "Dealer", true));
this.gridLookUpEditDealer.Properties.DataSource = this.dealers; // dealers = XPCollection
If i try:
this.gridLookUpEditDealer.EditValue = current.Dealer;
The LookUpEdit shows the value, but also "Value not valid"
I think the root cause is something that maybe the value in the Grid is not correctly bound as value in the LookUp. But what would be a correct way?
Upvotes: 0
Views: 1804
Reputation: 1690
Just another way to achieve the same result. With XPO, if you change the binding code as shown below, the GridLookUpEdit will update the order.Dealer property automatically.
this.gridLookUpEditDealer.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.mainGrid, "Dealer!", true));
I only added the exclamation sign behind the property name and can now remove this code:
Order order = gridView.GetRow(gridView.FocusedRowHandle); => shows an order
Dealer actDealer = this.gridLookUpEditDealer.EditValue as Dealer; => shows a Dealer
order.Dealer = actDealer; => lets the selected value vanish.
This feature was introduced specially for look-up editors and is described in this article: Property Descriptors.
Upvotes: 0
Reputation: 3979
I think the problem is, that you directly binding the whole Dealer. Set up your GridLookUpEdit as described in DevExpress Documentation.
So you should do following for your LookupEdit:
With something like this you get your DealerObject back:
Dealer dealer = GridLookUpEdit.Properties.GetRowByKeyValue(lookUpEdit.EditValue) as Dealer;
Because the EditValue will be your DealerId now. Further notice that you can use repositoryGridLookupEdit directly in your Offer Grid. So you don't need more then one Grid to show your information in a usable manner. Each offer is able to has a own Dealer-Column which holds a dealer. The repositoryLookupEdit allows you to edit the dealer within the Grid.
I hope this will help you. If not clarify your problem, i will assist you ;)
Upvotes: 1