Rad Data Grid not loaded only after second click

0 Answers 17 Views
DataGrid
Daniel
Top achievements
Rank 1
Silver
Bronze
Daniel asked on 09 Mar 2022, 10:21 AM | edited on 09 Mar 2022, 10:22 AM

Hi,

Problem:When I lick on button outside the grid only on second click I get data? why?


var historyReportViewModel = new HistoryReportViewModel();
        var historyReportResults = historyReportViewModel.CreateHistotyReport(resultsSelection, portalSelection, fromDateTimeSelection,
             selectionTypeSelection, routeSelection, toDateTimeSelection);

resultsDataGrid.ItemsSource = historyReportResults;



 <telerikDataGrid:RadDataGrid Grid.Row="4" Grid.Column="0" x:Name="resultsDataGrid" Margin="10"
                AutoGenerateColumns="False">
                <telerikDataGrid:RadDataGrid.BindingContext>
                    <local:HistoryReportViewModel />
                </telerikDataGrid:RadDataGrid.BindingContext>
                <telerikDataGrid:RadDataGrid.Columns>
                    <telerikDataGrid:DataGridTextColumn PropertyName="Succeded" HeaderText="Succeded"/>
                    <telerikDataGrid:DataGridTextColumn PropertyName="Type" HeaderText="Type"/>
                    <telerikDataGrid:DataGridTextColumn PropertyName="EndTime" HeaderText="End Time"/>
                    <telerikDataGrid:DataGridTextColumn PropertyName="File" HeaderText="File"/>
                    <telerikDataGrid:DataGridTextColumn PropertyName="Route" HeaderText="Route"/>
                    <telerikDataGrid:DataGridTextColumn PropertyName="FailedFolder" HeaderText="FailedFolder"/>
                    <telerikDataGrid:DataGridTextColumn PropertyName="Portal" HeaderText="Portal"/>
                </telerikDataGrid:RadDataGrid.Columns>
            </telerikDataGrid:RadDataGrid>

 

Didi
Telerik team
commented on 14 Mar 2022, 01:23 PM

I cannot reproduce the issue. 

Here is my xaml: 

    <Grid RowDefinitions="Auto,*">
        <Button Text="Add Data" Clicked="Button_Clicked"/>
        <telerikDataGrid:RadDataGrid x:Name="dataGrid"
          Grid.Row="1"
         AutoGenerateColumns="False">
            <telerikDataGrid:RadDataGrid.Columns>
                <telerikDataGrid:DataGridTextColumn PropertyName="Name"
                    HeaderText="Name"/>

                <telerikDataGrid:DataGridNumericalColumn PropertyName="StadiumCapacity"
                         HeaderText="Stadium Capacity"/>

            </telerikDataGrid:RadDataGrid.Columns>
        </telerikDataGrid:RadDataGrid>
    </Grid>

the viewmodel and data model: 

 public class ViewModel
    {
        public ViewModel()
        {
            this.Items = new ObservableCollection<Club>
            {
                new Club{ Name = "AAAAA"},
                new Club{ Name = "BBBBB"},
                new Club{ Name = "CCCCC"},
                new Club{ Name = "DDDDD"},
            };
        }
        public ObservableCollection<Club> Items { get; set; }
    }

    public class Club : INotifyPropertyChanged
    {
        private string name;

        public string Name
        {
            get { return this.name; }
            set 
            {
                if (this.name != value)
                {
                    this.name = value;
                    OnPropertyChanged();
                }
            }   
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

and the button clicked event in page's code behind:: 

 public partial class MainPage : ContentPage
    {
        ViewModel vm;
        public MainPage()
        {
            InitializeComponent();
            this.vm = new ViewModel();
            this.BindingContext = vm;

        }


        private void Button_Clicked(object sender, EventArgs e)
        {
            this.dataGrid.ItemsSource = this.vm.Items;
        }
    }

The result: 

 

You have to debug the code on your side and check when the DataGrid.ItemSource is populated with data. 

I hope this information will be of help. 

No answers yet. Maybe you can help?

Tags
DataGrid
Asked by
Daniel
Top achievements
Rank 1
Silver
Bronze
Share this question
or