We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

GridGroupingControl: how to update User Control inside a cell

Hi,

in my scenario I have:
- a "readonly" GridGroupingControl with a IBindingList as datasource
- my datasource list is updated by real time data
- one of the cell in each record is a custom User Control

Now, it's simple to set a User Control as CellType of one cell on each record (I used a custom CellModel and CellRenderer), but when datasource is updated I want to call a public method on the User Control of the modified record to update some info on that. How can I do that? Which are the events to intercept?

3 Replies

NK Neelakandan Kannan Syncfusion Team June 24, 2015 05:45 AM UTC

Hi Maurizio,

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



MZ maurizio ziraldo June 24, 2015 08:54 AM UTC

Hi Neelakandan,

your sample is useful to understand event to intercept, but my case need some more explanations.
I attached a new simplified version of the demo: as you can see in it I can add my personal User Control in the grid, but when I change the values of a row I cannot have access to it to call one on its method (see comments)
Thanks

Attachment: bindinglistdemo_d6afad8b.zip


NK Neelakandan Kannan Syncfusion Team June 25, 2015 05:25 AM UTC

Hi Maurizio,

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


Loader.
Live Chat Icon For mobile
Up arrow icon