1

我刚刚从 DataGrid 切换到 telerik RadGridView,现在加载数据所需的时间与我之前使用 DataGrid 加载时相比有很大的滞后。有人可以看看,让我知道我做错了什么,我是 WPF 的新手。

这是我的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>

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

这是我构建网格的代码

    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);
        }
    }
4

1 回答 1

3

检查他们的网站文档以了解提高性能的方法。我会链接,但目前在移动设备上。有一个专门用于 RadGridView 性能故障排除的项目。

我知道有几点是避免交替计数、无穷大的高度和宽度,以及 RadGridView 放置在什么控件中。

您还可以查看 Telerik 的“VirtualQueryableDataSource”(我认为它被称为)。它支持 UI 虚拟化。

编辑:( 直接来自 Telerik 支持票)

“然后,如果您将 GridView 放置在 TabControl 或 RadPaneGroup 中,请将包含控件的 IsContentPreserved 属性设置为 True。这样,每次在视图之间切换时,GridView 都不会重新加载。”

于 2013-07-16T05:25:35.980 回答