sfdatagrid not refreshing

Basically I'm displaing some objects data on the datagrid. I've a variable objHighlight that contains the id of the object I want highlight. I can change it with long press event. Iusse is that row not change color.

  private void myTableView_QueryRowStyle(object sender, QueryRowStyleEventArgs e)

  {

      var myobj = e.RowData as myobj;

      if (myobj != null && objHighlight == myobj.Id)

      {

          e.Style.BackgroundColor = Color.Yellow;

      }

  }

objHighlight contains the id of the object I want Highlighted.

and with press event I can change it:

 private void myobjTableView_GridLongPressed(object sender, GridLongPressedEventArgs e)

 {

     var rowData = e.RowData as myobj;

     if (rowData != null)

     {

        

         myobjHighlight = (int)rowData.Id;

         myobjTableView.Refresh();

     }

 }



3 Replies

SD Sethupathy Devarajan Syncfusion Team October 4, 2024 12:54 PM UTC

Hi Halcyon,

Based on the provided information, It seems that you're working on highlighting a specific row in the DataGrid based on an object ID and updating the highlighted row with a long press event. The issue you're experiencing, where the row's background color doesn't change as expected. We had achieved your query and shared both the simple sample and video demo for your reference.

regards,

Sethupathy D.


Attachment: XamarinBehaviouSolution_2a17e1a6.zip


HS Halcyon Security October 18, 2024 08:31 AM UTC

Thanks it worked fine. 

I've also another Iusse: I added this : 

 <syncfusion:SfDataGrid.GridStyle>

     <syncfusion:DefaultStyle HeaderBackgroundColor="Gray" HeaderForegroundColor="White"

           RowForegroundColor="White"

          SelectionBackgroundColor="Blue" SelectionForegroundColor="White"


          GridCellBorderColor="WhiteSmoke" HeaderCellBorderColor="WhiteSmoke" HeaderCellBorderWidth="2"

          AlternatingRowColor="DarkRed" RowBackgroundColor="Black" />

 </syncfusion:SfDataGrid.GridStyle>

but the row still all black and not alternated.


I'd like to add another feature to the example if possible:  in the model we have the properties: 

    private int? orderID;

    private string customerID;

    private string customer;

    private string shipCity;

    private string shipCountry;

    private bool isChecked;

Let's say that we map the orderID,CostumerID,shipCountry,IsChecked columns, the other are not visible. Then when the user tap the header of the customerID, I would remap this column to customer; same thing for shipCountry column: when header is tapped should be replaced by shipCity. Can it be done?



SD Sethupathy Devarajan Syncfusion Team October 21, 2024 12:55 PM UTC

Hi Halcyon,

Based on the information provided, it is clear that the alternativeRowBackground color is not updating in the UI. This issue occurs due to the definition of the QueryCellStyle event in the DataGrid. We have addressed this by setting the alternate row background within the QueryCellStyle event. For your reference, we have shared the relevant code snippet.

Code Snippet:

private void SfDataGrid_QueryRowStyle(object sender, QueryRowStyleEventArgs e)

{

    var myobj = e.RowData as OrderModel;

 

    if (myobj != null && myobjHighlight == myobj.OrderID)

    {

        e.Style.BackgroundColor = Color.Yellow;

    }

    else if(e.RowIndex % 2 == 0 && e.RowIndex > 0)

    {

        e.Style.BackgroundColor = Color.DarkRed;

    }

 

    e.Handled = true;

}


 

In addition to that, you had inquired about dynamically remapping columns. For example, mapping the OrderID, CustomerID, ShipCountry, and IsChecked columns, while the others remain hidden. Then, when the user taps the CustomerID header, it should be remapped to Customer, and similarly, when the ShipCountry header is tapped, it should be replaced by ShipCity.


We have successfully implemented both scenarios in the attached sample for your reference.


Regards,

Sethupathy D.


Attachment: XamarinBehaviouSolution_1e31403a.zip

Loader.
Up arrow icon