public class MyControl : RadControl |
{ |
MyElementPanel elementPanel; |
public MyControl() |
{ |
this.UseNewLayoutSystem = true; |
this.AutoSize = true; |
} |
protected override void CreateChildItems(RadElement parent) |
{ |
elementPanel = new MyElementPanel(); |
this.RootElement.Children.Add(elementPanel); |
base.CreateChildItems(parent); |
} |
public int Rows |
{ |
get |
{ |
return this.elementPanel.Rows; |
} |
set |
{ |
this.elementPanel.Rows = value; |
} |
} |
} |
public class MyElementPanel : RadItem |
{ |
StackLayoutPanel layout; |
public static RadProperty RowsProperty = RadProperty.Register( |
"Rows", |
typeof(int), |
typeof(MyElementPanel), |
new RadElementPropertyMetadata(2, ElementPropertyOptions.AffectsLayout)); |
public int Rows |
{ |
get |
{ |
return (int)this.GetValue(RowsProperty); |
} |
set |
{ |
this.SetValue(RowsProperty, value); |
} |
} |
protected override void CreateChildElements() |
{ |
var border = new BorderPrimitive(); |
Children.Add(border); |
var background = new FillPrimitive(); |
Children.Add(background); |
layout = new StackLayoutPanel(); |
layout.Orientation = System.Windows.Forms.Orientation.Vertical; |
this.Children.Add(layout); |
var rows = this.Rows; |
int rowHeight = (int)this.Size.Height / rows; |
for (int i = 0; i < rows; i++) |
{ |
var child = new RadLabelElement(); |
child.Text = (i + 1).ToString(); |
child.Margin = new System.Windows.Forms.Padding(1); |
child.Children[2].AutoSize = false; |
child.Children[2].Size = new Size(20, rowHeight); |
child.BorderVisible = true; |
layout.Children.Add(child); |
} |
base.CreateChildElements(); |
} |
protected override void OnPropertyChanged(RadPropertyChangedEventArgs e) |
{ |
if (e.Property == StorageRackElement.RowsProperty) |
{ |
var rows = (int)e.NewValue; |
int rowHeight = (int)this.Size.Height / rows; |
layout.Children.Clear(); |
for (int i = 0; i < rows; i++) |
{ |
var child = new RadLabelElement(); |
child.Text = (i + 1).ToString(); |
child.Margin = new System.Windows.Forms.Padding(1); |
child.Children[2].AutoSize = false; |
child.Children[2].Size = new Size(20, rowHeight); |
child.BorderVisible = true; |
layout.Children.Add(child); |
} |
} |
if (e.Property == StorageRackElement.BoundsProperty) |
{ |
int rowHeight = (int)this.Size.Height / this.Rows; |
foreach(var child in layout.Children) |
child.Children[2].Size = new Size(20, rowHeight); |
} |
base.OnPropertyChanged(e); |
} |
} |
Hi
I have an unbound radgridview and I am deleteing the row with an ID value of 0 the code runs but the row is still visible in the grid and when the radgridview is selected I get an error:
System.Data.RowNotInTableException was unhandled
Message="This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row."
Source="System.Data"
For x As Integer = 0 To Me. radgridview1.Rows.Count - 1
If (Me. radgridview1.Rows(x).Cells("ID").Value) = 0 Then
Me.Packagelist.Rows.RemoveAt(x)
Exit For
End If
Next
How do I remove the row from the grid and avoid the error?
Regards
Joe