Hey Guys
I have a problem where i wish to add logic into the CreateChildElements method which, based on the value of a given cell in the row will display different controls.
When CreateChildElements is called, the GridViewColumn and GridRowElement (which have been set in the contructor) are Null, as if they are not in the same context.
This is what i currently have (Please notice the CreateChildElements Method)
This is what i would like to do:
Please tell me if this is possible, or if there is an alternative way of doing this?
Many Thanks
Tim
I have a problem where i wish to add logic into the CreateChildElements method which, based on the value of a given cell in the row will display different controls.
When CreateChildElements is called, the GridViewColumn and GridRowElement (which have been set in the contructor) are Null, as if they are not in the same context.
This is what i currently have (Please notice the CreateChildElements Method)
#region GridDataCellElement
public
class
GridDataCustomCellElement : GridDataCellElement
{
#region Locals
private
RadImageButtonElement radButtonElementViewOrder;
private
RadImageButtonElement radButtonElementNewOrder;
public
GridViewColumn thisColumn;
public
GridRowElement thisRow;
#endregion
#region Constructors
public
GridDataCustomCellElement(GridViewColumn col, GridRowElement row) :
base
(col, row) { thisColumn = col; thisRow = row;}
#endregion
#region Events
void
radButtonElementNewOrder_Click(
object
sender, EventArgs e)
{
Main newOrder =
new
Main(GetFolderPath(thisRow.GridControl.CurrentRow.Cells[2].Value.ToString()) +
"\\"
+ thisRow.GridControl.CurrentRow.Cells[0].Value.ToString());
newOrder.MyParentForm = (SalesOrderingClient.Home)thisRow.GridControl.FindForm();
newOrder.IsCopyOrder =
true
;
newOrder.ShowDialog();
}
void
radButtonElementViewOrder_Click(
object
sender, EventArgs e)
{
// Build order object
SalesOrderingObjects.Order objOrder = SalesOrderingObjects.Order.LoadOrder(GetFolderPath(thisRow.GridControl.CurrentRow.Cells[2].Value.ToString()) +
"\\"
+ thisRow.GridControl.CurrentRow.Cells[0].Value.ToString());
// Build session object
Session s =
new
Session(objOrder);
// Display Order
Order o =
new
Order(s);
o.ShowDialog();
}
#endregion
#region Overrides
/// <summary>
/// Create new controls and add them to cell
/// </summary>
protected
override
void
CreateChildElements()
{
// Set up controls and add them to this cell
Home h =
new
Home();
radButtonElementViewOrder =
new
RadImageButtonElement();
radButtonElementViewOrder.ButtonFillElement.BackColor = Color.Transparent;
radButtonElementViewOrder.ButtonFillElement.BackColor2 = Color.Transparent;
radButtonElementViewOrder.ImageAlignment = ContentAlignment.MiddleRight;
radButtonElementViewOrder.BorderElement.Width = 0;
radButtonElementViewOrder.Image = h.IconImageLIst.Images[1];
radButtonElementViewOrder.ToolTipText =
"View Order"
;
this
.Children.Add(radButtonElementViewOrder);
radButtonElementNewOrder =
new
RadImageButtonElement();
radButtonElementNewOrder.ButtonFillElement.BackColor = Color.Transparent;
radButtonElementNewOrder.ButtonFillElement.BackColor2 = Color.Transparent;
radButtonElementNewOrder.ImageAlignment = ContentAlignment.MiddleRight;
radButtonElementNewOrder.BorderElement.Width = 0;
radButtonElementNewOrder.Image = h.IconImageLIst.Images[0];
radButtonElementNewOrder.ToolTipText =
"Copy Order"
;
this
.Children.Add(radButtonElementNewOrder);
radButtonElementNewOrder.Click +=
new
EventHandler(radButtonElementNewOrder_Click);
radButtonElementViewOrder.Click +=
new
EventHandler(radButtonElementViewOrder_Click);
}
/// <summary>
/// Set size and position of controls in the cell
/// </summary>
/// <param name="finalSize"></param>
/// <returns></returns>
protected
override
SizeF ArrangeOverride(SizeF finalSize)
{
// If there are more than 1 controls in this cell
//if (this.Children.Count == 3)
//{
// Setup dimensions and position and modifiy controls
RectangleF btn1 =
new
RectangleF(20, 12, 36, 36);
RectangleF btn2 =
new
RectangleF(58, 12, 36, 36);
this
.Children[0].Arrange(btn1);
this
.Children[1].Arrange(btn2);
//}
return
finalSize;
}
/// <summary>
/// Set the cells theme, if not done, cell does not inherit theme as it is custom
/// </summary>
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridDataCellElement);
}
}
public
override
bool
IsCompatible(GridViewColumn data,
object
context)
{
return
data
is
RadLabelColumn && context
is
GridDataRowElement;
}
#endregion
#region Private Methods
/// <summary>
/// Get folder path based on XML status
/// </summary>
/// <param name="status"></param>
/// <returns></returns>
string
GetFolderPath(
string
status)
{
string
folder =
string
.Empty;
switch
(status)
{
case
"Saved"
:
folder = Common.SavedOrdersFolder;
break
;
case
"InProgress"
:
folder = Common.InProgressOrdersFolder;
break
;
case
"Sent"
:
folder = Common.SentOrdersFolder;
break
;
case
"Requested"
:
folder = Common.RequestedOrdersFolder;
break
;
default
:
folder = Common.UserDataBaseFolder;
break
;
}
return
folder;
}
#endregion
}
#endregion
This is what i would like to do:
protected
override
void
CreateChildElements()
{
// Set up controls and add them to this cell
Home h =
new
Home();
switch
(SOMETHING GOES HERE)
{
case
?:
radButtonElementViewOrder =
new
RadImageButtonElement();
radButtonElementViewOrder.ButtonFillElement.BackColor = Color.Transparent;
radButtonElementViewOrder.ButtonFillElement.BackColor2 = Color.Transparent;
radButtonElementViewOrder.ImageAlignment = ContentAlignment.MiddleRight;
radButtonElementViewOrder.BorderElement.Width = 0;
radButtonElementViewOrder.Image = h.IconImageLIst.Images[1];
radButtonElementViewOrder.ToolTipText =
"View Order"
;
this
.Children.Add(radButtonElementViewOrder);
radButtonElementNewOrder =
new
RadImageButtonElement();
radButtonElementNewOrder.ButtonFillElement.BackColor = Color.Transparent;
radButtonElementNewOrder.ButtonFillElement.BackColor2 = Color.Transparent;
radButtonElementNewOrder.ImageAlignment = ContentAlignment.MiddleRight;
radButtonElementNewOrder.BorderElement.Width = 0;
radButtonElementNewOrder.Image = h.IconImageLIst.Images[0];
radButtonElementNewOrder.ToolTipText =
"Copy Order"
;
this
.Children.Add(radButtonElementNewOrder);
radButtonElementNewOrder.Click +=
new
EventHandler(radButtonElementNewOrder_Click);
radButtonElementViewOrder.Click +=
new
EventHandler(radButtonElementViewOrder_Click);
break
;
case
?:
// ADD SOME DIFFERENT CONTROLS
break
;
}
}
Please tell me if this is possible, or if there is an alternative way of doing this?
Many Thanks
Tim