Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My Problem Is That ..
I have multipel GridView Control On Windows From ...How to find GridView Control ..
What I Do??

What I have tried:

var Dgv = Cls_NDBO.GetControlByType(this, typeof(GridView));
           foreach (var control in Dgv)
           {
               // var grid = (GridView)control;
               GridView g = control as GridView;
               string intpu = grid.Name.Replace("Dgv_", string.Empty).ToString();
               Insertion(grid, intpu);
           }


internal static IEnumerable<Control> GetControlByType(Control control, Type type)
       {
           var controls = control.Controls.Cast<Control>();
           var enumerable = controls as Control[] ?? controls.ToArray();
           return enumerable.SelectMany(ctrl => GetControlByType(ctrl, type)).Concat(enumerable).Where(predicate: c => c.GetType() == type).OrderBy(c => c.TabIndex);
       }
Posted
Comments
CHill60 18-Jan-18 6:08am    
Well you have some code to call to get all of the GridViews on the Form (are you sure this is a WinForms app?). You could filter that list by the name of the GridView you want ... or step through each one as you are already doing.
What is wrong with the code you already have?
Altaf Ansari 18-Jan-18 23:48pm    
Are you creating DataGridView on Runtime??
please share you to better understand..
RizwanShaikh 22-Jan-18 2:12am    
var Dgv1 = GetControlByBaseType(this, typeof(GridControl));
foreach (GridControl control in Dgv1)
{
GridView grd = (GridView)control.MainView;
MessageBox.Show(grd.Name);
}

internal static IEnumerable<control> GetControlByBaseType(Control control, string type)
{
var controls = control.Controls.Cast<control>();
return controls.SelectMany(ctrl => GetControlByBaseType(ctrl, type)).Concat(controls).Where(c => c.GetType().BaseType.Name == type).OrderBy(c => c.TabIndex);
}
i have This method use sir..
my problem is sovle
RizwanShaikh 22-Jan-18 2:05am    
No Altaf Ansari.
I have creating design time datagridView.
RizwanShaikh 22-Jan-18 2:07am    
My Problem Is Sovle..
var Dgv = Cls_NDBO.GetControlByType(this, typeof(GridControl));
foreach (GridControl control in Dgv)
{
GridView grd = (GridView)control.MainView;

if (grd != grd_Subjects && grd != grd_Compulsory_Subjects)
{
string intpu = grd.Name.Replace("grd", string.Empty).ToString();
Cls_NDBO.Show_Wait_Form(splashScreenManager, "Dlete " + intpu);
Cmd = new SqlCommand("DELETE FROM SM_SUBJECT_GROUP_MASTER WHERE batch_no ='" + Cls_SM_Variables.Batch_No + "' AND class_id=" + cmb_Class.EditValue + " AND subject_group='" + Main_subject_grou + intpu + "' ", Cls_DBO.CMS3_Conn);
Cmd.ExecuteNonQuery();
}
}
This Method Is Used

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900