Hi,
I have a CellFormatting event in which i add a button to each cell in a particular column. so, i use e.CellElement.Children.Add(buttonInstance) inside the CellFormatting event (code for CellFormatting is below). The button is either enabled or disbaled based on the value of the cell.
void radGViewByLocation_CellFomatting(object sender, CellFormattingEventArgs e)
{
if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridTableHeaderRowElement))
{
if (e.CellElement.Children.Count > 0)
return;
GridViewDataColumn column = (GridViewDataColumn)e.CellElement.ColumnInfo;
if (column.FieldName == _ActivityTypeColumnName)
{
if (!(e.CellElement.RowInfo is GridViewDataRowInfo))
return;
GridViewDataRowInfo rowInfo = (GridViewDataRowInfo)e.CellElement.RowInfo;
if (rowInfo == null)
return;
// Since the collection object is held by the radGViewpeople, we just re-use it.
List<string> activityTypes = _collectionObj.ActivityTypeNames;
foreach (string activityTypeName in activityTypes)
{
try
{
if ((rowInfo.Cells.Count > 0) && (activityTypeName == rowInfo.Cells[4].Value.ToString()))
{
SubCollectionIdentfierClass subCollectionIdObject = new SubCollectionIdentfierClass();
// the people name appears in a different column depending on the user priviledge.
int index = 2;
subCollectionIdObject.location = radGViewByLocation.Rows[e.CellElement.RowIndex].Cells[index].Value.ToString();
subCollectionIdObject.people = radGViewByLocation.Rows[e.CellElement.RowIndex].Cells[index + 1].Value.ToString();
subCollectionIdObject.activityType = activityTypeName;
subCollectionIdObject.rowIndex = e.CellElement.RowIndex;
string buttonName = subCollectionIdObject.location + subCollectionIdObject.people + activityTypeName;
AIMButtonElement locationTypeElement = new AIMButtonElement();
locationTypeElement.Name = buttonName;
locationTypeElement.Tag = subCollectionIdObject;
locationTypeElement.Text = activityTypeName;
locationTypeElement.Image = _isCompleteItemImage;
locationTypeElement.TextAlignment = ContentAlignment.MiddleRight;
locationTypeElement.TextImageRelation = TextImageRelation.ImageBeforeText;
if (e.CellElement.Text == "false")
{
locationTypeElement.Enabled = false;
}
e.CellElement.Children.Add(locationTypeElement);
this.ApplyThemeToElement(locationTypeElement, "ControlDefault");
locationTypeElement.MouseDown += new MouseEventHandler(element_MouseDown);
locationTypeElement.MouseUp += new MouseEventHandler(element_MouseUp);
locationTypeElement.Click += new EventHandler(locationTypeElement_Click);
}
}
catch (Exception ex)
{
Logger.WriteLine("ERROR", "ANY", "Exception : <" + ex.Message + ">.");
}
} // foreach
}
}
}
Previously, i was trying to set the value of another cell in the same row as the event with GridViewDataRowInfo.Cells[1].Value but it led to a stackoverflow situation. So, i moved this code to a DataBindingComplete event. But now, when i check the CellElement in this event, they are all null so the code in the DataBindingComplete event does not get to the second if statement. So, where are the buttons and how do i get a handle to them so i can do what i need to in the DataBindingComplete event. Please help...
private void radGViewByLocation_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs eventArgs)
{
for (int j = 0; j < radGViewByLocation.Rows.Count; j++)
{
gvRow = radGViewByLocation.Rows[j];
if (gvRow.Cells[4].CellElement != null && gvRow.Cells[4].CellElement.Children != null)
{
if (gvRow.Cells[4].CellElement.Children.GetType() == typeof(AIMButtonElement))
{
AIMButtonElement theButton = (AIMButtonElement)gvRow.Cells[4].CellElement.Children[0];
SubCollectionIdentfierClass subCollectionIdObject = (SubCollectionIdentfierClass)theButton.Tag;
CollectionDataClass colDataObj = _collectionObj.GetCollectionDataBySubIdentifier(subCollectionIdObject);
if (colDataObj != null && colDataObj.IsCompleted)
{
theButton.DisplayStyle = DisplayStyle.ImageAndText;
// rowInfo.Cells[1].Value = true;
// radGViewByLocation.Rows[e.CellElement.RowIndex].Cells[1].Value = true;
gvRow.Cells[1].Value = true;
}
else
{
theButton.DisplayStyle = DisplayStyle.Text;
// rowInfo.Cells[1].Value = false;
// radGViewByLocation.Rows[e.CellElement.RowIndex].Cells[1].Value = false;
gvRow.Cells[1].Value = false;
}
}
}
}
}
thank you,
Bahram