Hi,
Among many other thing I'm using the WinGrid for displaying Orders coming from our Online Shop. Each row shows order related information that is coming out from a C# business object using data binding. There are also some icons displayed for each order like if the Order is an Upgrade, if it has been originated by one of our Resellers etc. Those icons are set in the InitializeRow event of the Grid with code like depicted in following snippet:
private void OnOrdersGridInitializeRow(object sender, InitializeRowEventArgs e)
{
/// Get the Order business object for that row var order = e.Row.ListObject as Order;
if (order != null) { UltraGridCell upgradeCell = e.Row.Cells["IsUpgradeCell"]; upgradeCell.Appearence = order.IsUpgrade ? grid.DisplayLaout.Appearances["UpgradeAppearance"] : null;
}
The appearance is set in the InitializeLayout event like depicted below:
private void OnOrdersGridInitializeLayout(object sender, InitializeLayoutEventArgs e)
{ Appearance isUpgradeAppearance = e.Layout.Appearances.Add["UpgradeAppearance"]; isUpgradeAppearance.ImageBackground = Resources.IsUpgrade;}
That all works perfectly fine but we also have a toolbar button allowing Sales staff to refresh the Grid so that newly arrived Orders coming from Online Shop are displayed. If they process an Order from top of the Grid and the Order will be removed from the Grid because it moves to another state this works still fine, the remaining Orders still show correct icons but as soon as the Grid is refreshed with new data from the database some of the icons are displayed wrong so e.g. the icon for Upgrade is not shown for an order although this order didn't change, showed the Upgrade icon before the Refresh. Basically the code couldn't be wrong otherwise it never would work but it is only not working correctly when the binding source is newly set.
Here is the code snippet when the Orders have been fetched from the database:
// Set the data source of binding source with the list of Orders received from the databaseorderBindingSource = fetchedOrdersFromDatabase;
// Make sure that InitializeRow event is fired otherwise the icons are not displayed appropriatelyordersGrid.Rows.Refresh(Refresh.FireInitializeRow, true);
orderBindingSource is a MS BindingSource used by the WinGrid for data binding, ordersGrid is the WinGrid object.
Could it be an issue because I'm calling the Refresh-method immediately after the binding source has been newly set? Is it necessary to wait for an event before calling Refresh or is there another preferred mechanism to be used to initialized displaying the icons compared to FireInitializeRow?
Thanks in advance,
Wolfgang
Hello Wolfgang,
Thank you for posting in our forum.
If I understand you correctly these are the steps you have performed:
1. You are creating an MS BindingSource and set its data source to some collection of orders.
2. You set the grid data source to this MS BindingSource.
3. Then you set some cells’ appearance depending on the cells’ value.
4. You perform some action on the rows and cells in the grid.
5. You set a new data source to your MS BindingSource.
Actually step one and step five should result in same behavior. In each row the cell IsUpgradeCell will have the custom appearance if the value of the cell is true. As you wrote if this works first time it should work and the second time. The only reason I can think of, why you are receiving wrong cells is if the data you are retrieving form the back end data server is correct. Can you please check if the data which you are retrieving on refresh button click is correct?
Please find attached also a small sample project I have created while was trying to reproduce this behavior with no success. Please try to modify this sample in order to demonstrate the behavior you are describing and send it back to me to investigate this further.
Looking forward to your reply.
Thank you for using Infragistics Components.
Hi Milko!
Thanks for your instant reply and the work you spent on creating this sample project!
The steps you've summed up are correct except step 4 because we don't modify the data by changing rows and cells directly in the Grid, this is done by other controls like text boxes, combo boxes, check boxes etc. outside of the grid but in same view so the changes done in those controls will be propagated into the Grid via the databinding. This is only an information so that you have a clear picture, the Grid is here just used for giving the user an overview of an Order and to select an individual order.
Your input, that the icons are displayed wrong due to getting it wrong from the database was also on my thoughts, I've asked our Sales staff to collect me those data because fortunately I've added a toolbar button which allows outputting a selected Order as XML-content so I can compare if the icons shown matches the Order structure :-) Since it doesn't always happen it will take some hours or days until I can verify that.
I've had a look to your sample code, it comes rather close to our implementation but there are some differences I didn't mention in my original posting:
I've tried to simulate the first 2 issues in your sample solution but it works fine there but I couldn't verify it in my test system where same code as in Live System runs. I'll wait for the feedback of our Sales staff to see if the data from database is wrong because then it is an issue on our side. Will come back if I need further assistance from your side.
I've added the modified sample project. There is a second button which removes the top most order from the Grid each time you press it. I've added a Thread.Sleep call in constructor of Order object. This is only to have some gap in the SubmittedAt column between the Order objects. Otherwise they more or less have same DateTime, sorting may look little bit weird :-)