C# .NET - Find gridview in devexpress gridcontrol using name of the gridview

Asked By Somanathan E on 22-Jun-12 08:14 AM
How to find a specific view by providing the name of the gridview to gridcontrol ?.
Is there any way to get the gridview object by only knowing its name .
[)ia6l0 iii replied to Somanathan E on 22-Jun-12 12:31 PM
Good Q. 

The GridControl has a property called as ViewCollection, that returns the views in the grid. Note that this would only contain the views that are used. These include the "Mainview"  and the "clone" view.

You would need to loop thru the collection and figure out the grid inside this view collection. Please see below for a sample.

for (int counter = 0; counter < gridControl.ViewCollection.Count; counter++)
                if (gridControl.ViewCollection[counter].GetType() == typeof(GridView))
GridView gv = (GridView)gridControl.ViewCollection[counter] as GridView;
        //Use its name property and determine the gridview

Hope this helps.
Somanathan E replied to [)ia6l0 iii on 22-Jun-12 01:03 PM
Thanks for your very useful reply.
[)ia6l0 iii replied to Somanathan E on 22-Jun-12 01:10 PM
Glad to help!
Jitendra Faye replied to Somanathan E on 25-Jun-12 01:24 AM
For this you can simply iterate ViewCollection in GridControl.

Try to find like tis-

foreach (ViewCollection view in gridControl.ViewCollection)
          if (view.GetType() == typeof(GridView))
                   GridView grdview= (GridView) view as GridView;

TRy this and let me know.