private
void
someOtherMethod ()
{
sysParentDropDown.DataSource = dt;
sysParentDropDown.DisplayMember =
"name"
;
sysParentDropDown.ValueMember =
"panelid"
;
sysParentDropDown.SelectedIndex = -1;
}
private
void
sysParentDropDown_SelectedIndexChanged(
object
sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if
(
this
.sysParentDropDown.SelectedIndex > -1)
{
sysDeviceDropDown.Enabled =
true
;
try
{
sysDeviceDropDown.DataSource =
null
;
sysDeviceDropDown.Text =
null
;
sysInputDropDown.DataSource =
null
;
sysInputDropDown.Text =
null
;
DataRowView drv = (DataRowView)
this
.sysParentDropDown.SelectedItem.Value;
string
s =
"(panelid = "
+ drv.Row[
"panelid"
].ToString() +
") AND (devid <> 0) AND (inputdevid = 0)"
;
DataRow[] foundRows = deviceNames.Select(s,
"name asc"
);
DataTable dt =
new
DataTable(
"temp"
);
dt.Columns.Add(
"name"
);
dt.Columns.Add(
"devid"
);
foreach
(DataRow dr
in
foundRows)
{
dt.ImportRow(dr);
}
DataRow row = dt.NewRow();
row[
"name"
] =
""
;
row[
"devid"
] =
" "
;
dt.Rows.InsertAt(row, 0);
sysDeviceDropDown.DisplayMember =
"name"
;
sysDeviceDropDown.ValueMember =
"devid"
;
sysDeviceDropDown.DataSource = dt;
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
sysDeviceDropDown.Enabled =
false
;
sysDeviceDropDown.SelectedText =
null
;
sysInputDropDown.Enabled =
false
;
sysInputDropDown.SelectedText =
null
;
}
}
private void gv_UserAddedRow(object sender, GridViewRowEventArgs e)
{
gv.CurrentRow = gv.MasterView.TableAddNewRow;
gv.CurrentColumn = gv.Columns[0];
gv.BeginEdit();
}
Hi
Users of my app some time ago reported issue with memory leak, so I started investigation and it looks that there is problem with RadGridView.
This is my sample code:
public
partial
class
Form1 : Form
{
BindingList<Package> _packages =
new
BindingList<Package>();
BindingList<PackageItem> _items =
new
BindingList<PackageItem>();
public
Form1()
{
InitializeComponent();
radGridView1.DataSource = _packages;
radGridView1.ReadOnly =
true
;
GridViewTemplate viewItemsTemplate =
new
GridViewTemplate();
viewItemsTemplate.DataSource = _items;
this
.radGridView1.MasterTemplate.Templates.Add(viewItemsTemplate);
GridViewRelation relation =
new
GridViewRelation(radGridView1.MasterTemplate);
relation.RelationName =
"myRelation"
;
relation.ChildTemplate = viewItemsTemplate;
relation.ParentColumnNames.Add(
"Id"
);
relation.ChildColumnNames.Add(
"PackageId"
);
this
.radGridView1.Relations.Add(relation);
_packages.Add(
new
Package() { Id =
"1"
, Name =
"Package1"
});
_items.Add(
new
PackageItem() { Id =
"1"
, PackageId =
"1"
, Name =
"Item1 in package1"
});
_items.Add(
new
PackageItem() { Id =
"2"
, PackageId =
"1"
, Name =
"Item2 in package1"
});
_packages.Add(
new
Package() { Id =
"2"
, Name =
"Package2"
});
_items.Add(
new
PackageItem() { Id =
"3"
, PackageId =
"2"
, Name =
"Item1 in package2"
});
_items.Add(
new
PackageItem() { Id =
"4"
, PackageId =
"2"
, Name =
"Item2 in package2"
});
radGridView1.BestFitColumns();
}
private
void
btnDelete_Click(
object
sender, EventArgs e)
{
radGridView1.BeginUpdate();
PackageItem pi = _items[0];
_items.Remove(pi);
radGridView1.EndUpdate();
}
}
When I delete row I call BeingUpdate() and EndUpdate(), this is needed – without these calls row is not deleted and after click on row exception is thrown.
TO SEE this problem before deleting row YOU HAVE TO expand child rows!
I used profiler and I have seen that there are types that hook this event and do not unhook after disposing! These types are: GridDetailViewCellElement, GridDetailViewRowElement, GridTableElement. You can check details in screen shots.
How can I solve this problem? This is really urgent issue for me – I have a lot of updates in my grid and after couple hours there is always out of memory exception caused by my app.
Regards