Robert
Robert

Reputation: 666

switched from DataGrid to telerik RadGridView now preformance issues using WPF

I just switched from DataGrid to telerik RadGridView and now there is a big lag in the time it takes to load my data vs before when i was using DataGrid it loaded right up. Can someone take a look and let me know what i am doing wrong i am new to WPF.

herer is my xaml:

<DockPanel Name="dpHistory" LastChildFill="True" sl:UIAudit.Drsapplication="EMR" sl:UIAudit.Drsarea="SuperBillHistory">
        <telerik:RadGridView Name="dgData" telerik:StyleManager.Theme="Summer" CanUserDeleteRows="False" IsReadOnly="True"  AutoGenerateColumns="False" Grid.ColumnSpan="2" RowHeight="25"
                             ShowGroupPanel="False" 
                             IsFilteringAllowed="False" 
                             CanUserReorderColumns="False"
                             RowIndicatorVisibility ="Collapsed"
                             EnableRowVirtualization="True"
                             EnableColumnVirtualization="True"
                             FrozenColumnCount="2"
                             SelectionUnit="FullRow"
                             SelectionMode="Extended"
                             AlternationCount="2"
                             AlternateRowBackground="LightSteelBlue">
        </telerik:RadGridView>
</DockPanel>

==================================================================================

here is my code to build the girds

    public void LoadHistory(Patient patient, ApptData appointment, DaysOfHistory_Enum daysOfHistory = DaysOfHistory_Enum.SixMonths)
    {
        if (patient.PatientId != intPatientId || reload || currentNextAppt || isNextAppt)
        {

            intDaysOfHistory = (-1) * ((int)daysOfHistory);

            currentNextAppt = isNextAppt;

            activePatient = patient;
            activeAppt = appointment;
            intPatientId = activePatient.PatientId;
            intApptId = appointment.ApptId;

            reload = false;

            if (isNextAppt)
            {
                LoadNextApptHistory();
                return;
            }

            DataSet ds = null;

            if (isTreatment)
            {
                ds = DrScribe.SharedLib.Application.WebService.ExecuteQuery("emr_selectTreatmentHistory", new SPParam[] {
                new SPParam("@PatientId", intPatientId),
                new SPParam("@StartDate", activeAppt.ApptDate.AddDays(intDaysOfHistory)) });
            }
            else
            {
                ds = DrScribe.SharedLib.Application.WebService.ExecuteQuery("emr_selectSuperBillHistory2", new SPParam[] {
                new SPParam("@PatientId", intPatientId),
                new SPParam("@StartDate", activeAppt.ApptDate.AddDays(intDaysOfHistory)) });
            }
            DataTable table = ds.Tables[0];

            DataTable dataTable = new DataTable("tableData");

            Dictionary<string, DateTime> dates = new Dictionary<string, DateTime>();
            Dictionary<string, int> rownum = new Dictionary<string, int>();

            dateView = new DataView(table);
            dateView.Sort = "ApptDate desc";

            foreach (DataRowView dr in dateView)
            {
                String date = formatDate(dr["ApptDate"].ToString(), "_");

                if (!dates.ContainsKey(date))
                {
                    dates.Add(date, DateTime.Parse(dr["ApptDate"].ToString()));
                }
            }

            dataTable.Columns.Add(new DataColumn("Code", Type.GetType("System.String")));
            dataTable.Columns.Add(new DataColumn("Description", Type.GetType("System.String")));

            foreach (string date in dates.Keys)
            {
                dataTable.Columns.Add(new DataColumn("ApptDate" + date, Type.GetType("System.String")));
            }

            foreach (DataRow dr in table.Rows)
            {
                string key = dr["Code"] + "_" + dr["Description"];
                if (!rownum.ContainsKey(key))
                {
                    DataRow row = dataTable.NewRow();
                    rownum.Add(key, rownum.Count);
                    dataTable.Rows.Add(row);
                    row["Code"] = dr["Code"];
                    row["Description"] = dr["Description"];
                }
            }

            foreach (DataRow dr in table.Rows)
            {
                string key = dr["Code"] + "_" + dr["Description"];
                int row = (int)rownum[key];

                string date = formatDate(dr["ApptDate"].ToString(), "_");

                string result = string.Empty;
                if (dr["Dosage"].ToString() != string.Empty)
                    result = dr["Dosage"].ToString();
                else if (dr["Units"].ToString() != string.Empty)
                    result = dr["Units"].ToString();

                dataTable.Rows[row]["ApptDate" + date] = result;
            }
            dataTable.AcceptChanges();

            dgData.Columns.Clear();

            dgData.Columns.Add(new Telerik.Windows.Controls.GridViewDataColumn() { DataMemberBinding = new Binding("Code"), Header = "Code", Width = new GridViewLength(75) });
            dgData.Columns.Add(new Telerik.Windows.Controls.GridViewDataColumn() { DataMemberBinding = new Binding("Description"), Header = "Description", Width = new GridViewLength(250) });

            foreach (string date in dates.Keys)
            {
                Binding b = new Binding("ApptDate" + date);

                CheckmarkConverter c = new CheckmarkConverter();

                b.Converter = c;

                GridViewDataColumn t = new GridViewDataColumn();
                t.DataMemberBinding = b;
                t.Header = date.Replace("_", "/");
                t.Width = new GridViewLength(70);

                dgData.Columns.Add(t); //new DataGridTextColumn() { Binding = new Binding("ApptDate" + date), Header = date.Replace("_", "/"), Width = new DataGridLength(70) });
            }

            dgData.ItemsSource = new DataView(dataTable);
        }
    }

Upvotes: 1

Views: 3450

Answers (1)

Kcvin
Kcvin

Reputation: 5163

Check their website documentation for ways to increase performance. I would link but currently on mobile. There is a dedicated item to RadGridView performance troubleshooting.

I know a couple points are avoid alternation count, infinity heights and width, and what control the RadGridView is placed in.

You can also look into Telerik's 'VirtualQueryableDataSource' (I think its called). Its supports UI Virutalization.

Edit: (striaght from Telerik support ticket)

"Then, if you place the GridView inside a TabControl or a RadPaneGroup, please set the IsContentPreserved property of the containing control to True. That way the GridView will not be reloaded every time when you switch between the views."

Upvotes: 3

Related Questions