GoXuni / Legacy-Xuni-Xamarin.Forms

These samples show how to use all features of Xuni in Xamarin.Forms.
14 stars 12 forks source link

flexgrid binding? selection row #7

Open PlusInf0Iulia opened 7 years ago

PlusInf0Iulia commented 7 years ago

Hello i have some problems with the flexgrid. First of all on Android don't shows the rows event if the event CellFactory and AutoGeneratingColumn are called. this is my code: context = new VMAzioniGrid(_filtri); BindingContext = context;

        FlexGrid grid = new FlexGrid();
        grid.SetBinding(FlexGrid.ItemsSourceProperty, "data");
        grid.SetBinding(FlexGrid.IsVisibleProperty, "lvvisibil");
        grid.ColumnHeaderBackgroundColor = GlobalVariables.BackColorGrigioDark();
        grid.ColumnHeaderTextColor = Color.White;
        grid.GridLinesVisibility = GridLinesVisibility.Horizontal;
        grid.AllowSorting = true;
        grid.SelectionMode = GridSelectionMode.Row;
        context.mostraTuttiQueryExecute();
        grid.AutoGeneratingColumn += OnAutoGeneratingColumn;
        grid.SelectionChanged += OnSelectionChanged;
        grid.CellFactory = new MyCellFactory();
        this.Children.Add ( new StackLayout { Children = { grid } });
        firstLoad = true;

private void OnAutoGeneratingColumn(object sender, GridAutoGeneratingColumnEventArgs e) { //System.Diagnostics.Debug.WriteLine("viewAzioniGrid - OnAutoGeneratingColumn"); System.Diagnostics.Debug.WriteLine("viewAzioniGrid - OnAutoGeneratingColumn - e.Property.Name: " + e.Property.Name);

        var queries = QueriesListData.getQueryById(_queriesId);
        var fields = queries.qFieldsList;
        Dictionary<string, string> dizionariocolonna;
        //var dizionariocolonna = new Dictionary<string, string>();
        if (fields.TryGetValue(e.Property.Name, out dizionariocolonna))
        {
            e.Column.Header = dizionariocolonna["headerText"];
            e.Column.Width = new GridLength(Convert.ToDouble(dizionariocolonna["width"]));
            e.Column.IsVisible = Convert.ToBoolean(dizionariocolonna["visible"]);

        }
        else { e.Column.IsVisible = false; }
        //var fieldtemplate = queries.qFieldsTemplate;
        //Type cTemplate;
        //if (fieldtemplate.TryGetValue(e.Property.Name, out cTemplate)) { 
        //  System.Diagnostics.Debug.WriteLine("viewAzioniGrid - OnAutoGeneratingColumn - cell template - e.Property.Name: " + e.Property.Name);
        //  //var cTemplateInstance=(ViewCell)Activator.CreateInstance(cTemplate);
        //  e.Column.CellTemplate =new DataTemplate(cTemplate);
        //}
        //System.Diagnostics.Debug.WriteLine("viewAzioniGrid - OnAutoGeneratingColumn FINE");
        //System.Diagnostics.Debug.WriteLine("viewAzioniGrid - OnAutoGeneratingColumn");

    }

public class MyCellFactory : GridCellFactory { /// /// Override BindCellContent to customize the cell content /// public override void BindCellContent(GridCellType cellType, GridCellRange range, View cellContent) { Guid f = Guid.NewGuid(); System.Diagnostics.Debug.WriteLine(f + " BindCellContent"); base.BindCellContent(cellType, range, cellContent); var label2 = cellContent as Label; System.Diagnostics.Debug.WriteLine(f + " cellType " + label2.Text); System.Diagnostics.Debug.WriteLine(f + " range.Column " + range.Column.ToString());

        base.BindCellContent(cellType, range, cellContent);
        //if (cellType == GridCellType.Cell && cellType != GridCellType.ColumnHeader && range.Column == 9)
        //{
        //  var label = cellContent as Label;
        //  if (label != null)
        //  {
        //      var originalText = label.Text;
        //      if (originalText == "4")
        //      {
        //          label.Text = "Nuova";
        //      }
        //      else if (originalText == "2")
        //      {
        //          label.Text = "Chiusa";
        //      }
        //      else if (originalText == "1")
        //      {
        //          label.Text = "Iniziata";
        //      }
        //      else if (originalText == "3")
        //      {
        //          label.Text = "Sospesa";
        //      }
        //      //double cellValue;
        //      //if (double.TryParse(originalText, out cellValue))
        //      //{
        //      //  label.TextColor = cellValue < 70.0 ? Color.Red : Color.Green;
        //      //  label.Text = String.Format("{0:n2}", cellValue);
        //      //}
        //  }
        //}
        if (cellType == GridCellType.Cell && cellType != GridCellType.ColumnHeader && range.Column == 4)
        {
            var label = cellContent as Label;
            if (label != null)
            {
                var originalText = label.Text;
                if (originalText != "")
                {
                    label.Text = Convert.ToDateTime(originalText).ToString("dd/MM/yyyy HH:mm");

                }
                else
                {
                    label.Text = "-";
                }
            }

        }

    }
}

Then on IOs it's always selected the last row. Why? i don't know if it's happen even on android because i don't see the rows. And a last question is there a way to do paging in the grid? Thank you