我刚刚从 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);
}
}