I try to dynamically add datasource to RepositoryItemSearchEdit on EditorShown event.
However when doing this the BusinessObject.ToString value is not displayed in grid cell when it is not edited.
On the other hand it is displayed when datasource is added on FormLoad.
Why? I thought editors datasource is not used when the editor is not displayed...
To reproduce the problem in the attached project:
- add new row;
- select something from Receiver column (editor is displayed normally);
- move to other cell.
If you comment out the EditorShown handle and in the form load change the LoadClientInfoListToSearchLookUpEdit last param DoNotLoadDataSource to false, everything works perfectly.
So I assume the problem lays in the dynamically adding datasource...
Thank you for your message.
It is correct behavior. When you do not click within a cell, an in-place editor is not created, and its pattern RepositoryItem is used to define how cells should be shown in a grid. I recommend that you review the Repositories and Repository Items help article for more information regarding this. That is why, it is necessary to originally set the RepositoryItemSearchLookUpEdit.DataSource property.
I suggest that you review the How to filter a second LookUp column based on a first LookUp column's value example to learn how to filter a lookup datasource in the GridView.ShownEditor event handler.
Another solution is to create some RepositoryItemSearchLookUpEdit items with different datasources and assign them to individual cells in the GridView.CustomRowCellEdit event.
I hope that my explanation will make things clearer. If not, let us know.
But i'm doing just the same thing as in the example:
example: edit.Properties.DataSource = New BindingSource(clone, "")
me: edit.Properties.DataSource = GetBindingSourceForCachedList( _
GetType(CostsEstimatesItemInfoList), SelectedItem.Project.ID, True)
If I preset datasource to the meaningless data of the same type the grid shows correct items even if these items does not exist in the datasource.
But if I change the datasource in the EditorShown event afterwards as in the example, the cell gets blank even though it holds correct business object and the object is contained within datasource. Other rows in the column are not affected though they are supposed to if they share datasource.
Where is the logic?
Found solution by myself.
"and its pattern RepositoryItem is used to define how cells should be shown in a grid" - it is not necessarily so.
Actually after being hidden an edit control sets a cell value which becomes independent from the datasource of the edit control. This value can be later retrieved by the GetRowCellValue method irrespective of the edit control's datasource state (same/changed/disposed). It's just like in the MS grid.
However it seems that the edit control is used to format the displayed cell's text for some unknown reason. Such behavior is fundamentally flawed because a user/developer could reasonably wish different formating for edit/view modes. Furthermore both GridColumn and EditControl provide DisplayFormat properties which creates an illusion that it is easily done. And illusions aren't good for developer's mental health.
The workaround revealed to be extremely trivial. (though it took 6 hours of experimenting) If you handle GridView.CustomColumnDisplayText event, you are free to manipulate EditControl's datasource at your own discretion.
Private Sub GridView1_CustomColumnDisplayText(ByVal sender As Object, _
ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs) _
If Not e.Column Is colCostsEstimates Then Exit Sub
If e.Value Is Nothing Then
e.DisplayText = ""
e.DisplayText = e.Value.ToString
I am glad to hear that you have resolved this problem. However, I will try to explain the GridControl's and editors' behavior:
>>But i'm doing just the same thing as in the example:
In the example, RepositoryItem.Datasource is assigned by default. Thus, its data is used to draw cell values.
>>Actually after being hidden an edit control sets a cell value which becomes independent from the datasource of the edit control.
Yes, you are right. An editor sets a value to a cell, and this value is independent from the datasource. However, GridControl uses the RepositoryItem methods to draw cell content. RepositoryItemSearchEdit does not show a value if it is not contained in the editor datasource.
>> However it seems that the edit control is used to format the displayed cell's text for some unknown reason.
The RepositoryItem methods are used for drawing the entire cell content, formating and masking. The Masking functionality is available only at the RepositoryItem level.
>>user/developer could reasonably wish different formating for edit/view modes.
You can customize different formating for the edit and display modes at the RepositoryItem level. You can use several properties to do this: DisplayFormat, EditFormat, Mask, CustomDisplayText, etc.
GridControl provides methods to customize formating only in the display mode: CustomColumnDisplayText, DisplayFormat, etc.
>>Furthermore both GridColumn and EditControl provide DisplayFormat properties which creates an illusion that it is easily done.
An edit value can be formated both at the gridControl level and the editor level. GridControl and editors provide several methods to format the value and change the displayed text. They are called sequentially to implement the required formating.
I hope you will find this information useful. If you need any further assistance with this subject, please feel free to reactivate this ticket.
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.