GridGroupingControl: how to update User Control inside a cell
Thank you for using Syncfusion products.
If you want to set the content or data to the particular cell from modified records in grid while updating, you can use SourceListListChangedCompleted event. This event will be triggered once data is updated to the grid. Here we have provided simple sample. In this sample, custom cell type cell value will be changed once data is updated to grid. Please make use of below code,
Code Snippet:
this.gridGroupingControl1.SourceListListChangedCompleted += gridGroupingControl1_SourceListListChangedCompleted;
void gridGroupingControl1_SourceListListChangedCompleted(object sender, TableListChangedEventArgs e)
{
//Used to check whether record is modified
if (e.ListChangedType == ListChangedType.ItemChanged)
{
//Used to get the record value from modified record
string recordValue = this.gridGroupingControl1.Table.Records[e.NewIndex].GetValue("Description").ToString();
//Used to check the record value of modified record from particular column(which has custom control)
if (recordValue == "Descnew")
{
int colIndex = 2;//Custom celltype column index
int topRowIndex=this.gridGroupingControl1.TableControl.TopRowIndex;
int leftColIndex=this.gridGroupingControl1.TableControl.LeftColIndex;
//Used to set the custom celltype cellvalue
GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(e.NewIndex + topRowIndex, leftColIndex + colIndex);
style.TableCellIdentity.DisplayElement.GetRecord().SetValue("Description","Sample");
//To refresh the data
e.Table.TableDirty = true;
}
}
}
Sample:
http://www.syncfusion.com/downloads/support/forum/119452/ze/Sample_Custom_CellType_Update1025394026
Please let me know if you have any concerns.
Regards,
Neelakandan
Attachment: bindinglistdemo_d6afad8b.zip
Thank you for update.
We have analyzed your sample at our end. Since GridGroupingControl does not support cell based style setting in code level other than QueryCellInfo event, the reported case with “Changing the particular cell value or accessing the object of custom cell” cannot be possible. In our previous sample which uses LinkLabelCell custom cell, the text for that cell will be changed if it is set in record value. More importantly this cell renderer has not any external UserControl. So that the cell value will be automatically changed. As per your custom cell (MyControl) it uses Label to set the text for that cell. So text should be assigned in OnDraw event in CellRenderer. Other than this there is no possibility to access the object.
Moreover you can set the text for that cell as follows,
Code Snippet:
protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
{
try
{
style.Control = control;
//**************************************************************
//you need to set the text for custom cell in this place.
//Because for every time, this event will be called and the text for this cell can be assigned if we set LabelText of that control.
//So that the below way is the possible method to assign the text as default.
//control object is assigned for every cell in this place.
//**************************************************************
if (style.CellIdentity is GridTableCellViewStyleInfoIdentity)
{
GridTableCellViewStyleInfoIdentity id = style.CellIdentity as GridTableCellViewStyleInfoIdentity;
GridControlBase grid = id.GetActiveGridView() as GridControlBase;
if (grid is GridTableControl)
{
control.Update(id.DisplayElement.GetRecord().GetValue("val2").ToString());
}
}
base.OnDraw(g, clientRectangle, rowIndex, colIndex, style);
}
catch (Exception e)
{
Console.WriteLine("ERROR: " + e.Message);
}
}
Modified sample:
http://www.syncfusion.com/downloads/support/forum/119452/ze/Sample_Modified-276232000
Please let me know if you have any concerns.
Regards,
Neelakandan
- 3 Replies
- 2 Participants
-
MZ maurizio ziraldo
- Jun 23, 2015 01:06 PM UTC
- Jun 25, 2015 05:25 AM UTC