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.
Unfortunately, activation email could not send to your email. Please try again.

How to access dynamically created GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

88083 Jul 14,2009 02:10 PM Jul 21,2009 01:32 AM Windows Forms 2
loading
Tags: GridControl
Pete Davis
Asked On July 14, 2009 02:10 PM

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.

Pete Davis
Replied On July 15, 2009 11:15 AM

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?

Thomas K [Syncfusion]
Replied On July 21, 2009 01:32 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;