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

How to access dynamically created GridDataBoundGrid

Hi there.

I'm currently building an application that is using a .net TabControl. Each TabPages of the TabControl are being dynamically created durring run-time and can range in number from 1 to 10. Each TabPage contains several Label and TextBox Controls and one Syncfusion GridDataBoundGrid control.

I am able to populate the GridDataBoundGrid control with data when I first create the control. The GridDataBoundGrid is editable to the user, so they are able to change the contents of cells and add or delete rows, so I need to be able to access the data from the control so that I can save it to database.

The problem I am having is accessing the the control (more specifically the data in it) after it's created.

Here is how I am currently accessing the contols on the TabPages:

foreach (TabPage tab in tabControl1.Controls)
{
foreach (Control ctrl in tab.Controls)
{
if (control is TextBox)
{
//Example of accessing my the data in my TextBox controls:
string test = control.Text;
}
else if (ctrl is GridDataBoundGrid)
{
//Not sure what to do here?
}
}
}

I've tried to typecast the control to a GridDataBoundGrid but that's not working, as in it's not allowing me to access the "Model" subclass to access the data in the cells.

Please give advice on how I should proceed.

Thank you.

2 Replies

PD Pete Davis July 15, 2009 03:15 PM UTC

Finally figured it out.

I was trying to access the cells by doing something like this:

foreach (Control ctrl in tab.Controls)
{
if(ctrl is GridDataBoundGrid)
{
string myString = (GridDataBoundGrid)control.Model[1, 1].Text
}
}

This was not working though, as I technically was not able to access the subclasses of GridDataBoundGrid such as "Model".

The solution (or a solution) is to create a new instance of GridDataBoundGrid and assign it the value of the control. This will allow you to access the subclasses of the GridDataBoundGrid class. Example:

foreach (Control ctrl in tab.Controls)
{
if(ctrl is GridDataBoundGrid)
{
GridDataBoundGrid grid = (GridDataBoundGrid)control;
string myString = grid.Model[1, 1].Text;
}
}

P.S. Why does this forum not support tabbed white space?


TK Thomas K Syncfusion Team July 21, 2009 05:32 AM UTC

Hi,

Currently, we do not have tabbed spacing support in textarea while posting forums. We will implement this feature in our future website releases.

We regret for any inconvenience caused.

Regards,
Thomas

Loader.
Live Chat Icon For mobile
Up arrow icon