AD
Administrator
Syncfusion Team
April 27, 2005 04:17 PM UTC
Please someone reply!
Please tell me whether it is possible or not.
Please do reply!
>I have a GDBG attached to my form.
>
>I have added 5 columns to the GridBoundColumns collection. Now at the run time I am trying to get the name of the GridBoundColumns columns but I can’t get it.
>
>I am using the following code
>
>foreach (GridBoundColumn column in c.GridBoundColumns)
>{
> MessageBox.Show(column.Name); // Not working
> TreeNode node = nodes.Add(column.MappingName); // Working
> node.Tag= column.MappingName;
>}
>
>get the following error
>
>“C:\ref3\ClassLibrary1\Class11.cs(239): ''Syncfusion.Windows.Forms.Grid.GridBoundColumn.Name'' is inaccessible due to its protection level
>
>I need actual column name, I don’t want Mapping name.
>
>Please provide some help.
>
>Thanks
>
AD
Administrator
Syncfusion Team
April 27, 2005 05:11 PM UTC
Do you want the underlying column name of the DataSet or the text that is displaying?
Regards,
Thomas
AD
Administrator
Syncfusion Team
April 27, 2005 07:13 PM UTC
I need to get the actual column name.
When you add the columns to GDBG GridBoundColumns collection, it gives them some name like
private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn1;
private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn2;
private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn3;
private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn4;
private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn5;
You can map these columns to the columns of a dataset.
Now you can get the name of the dataset columns Using
foreach (GridBoundColumn column in c.GridBoundColumns)
{
MessageBox.Show(column.MappingName)
}
BUT THIS IS NOT WHAT I WANT.
I need to get the actual column names i.e. gridBoundColumn1, gridBoundColumn2 ……
Please do help.
Thanks
AD
Administrator
Syncfusion Team
April 27, 2005 08:40 PM UTC
The names you''re talking is the GridBoundColumn object itself. I''m really not shure what you need? Tell what you like to do when you know the name of the column, maybe I can give you a better answer.
Regards,
Thomas
>
>I need to get the actual column name.
>
>When you add the columns to GDBG GridBoundColumns collection, it gives them some name like
>
>private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn1;
>private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn2;
>private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn3;
>private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn4;
>private Syncfusion.Windows.Forms.Grid.GridBoundColumn gridBoundColumn5;
>
>You can map these columns to the columns of a dataset.
>
>Now you can get the name of the dataset columns Using
>
>foreach (GridBoundColumn column in c.GridBoundColumns)
>{
> MessageBox.Show(column.MappingName)
>}
>
>BUT THIS IS NOT WHAT I WANT.
>
>I need to get the actual column names i.e. gridBoundColumn1, gridBoundColumn2 ……
>
>Please do help.
>
>Thanks
>
>
>
AD
Administrator
Syncfusion Team
April 27, 2005 09:07 PM UTC
Okay,
Sorry for any confusion.
I am creating an interface where I provide user with all the controls on a form in a tree view structure. I have attached a sample of my interface.
Now if I have a GDBG on my form , user wants to see all the columns within that grid. Based on what columns of a grid user select, I need to apply some format changes to those selected columns of a grid in next runs of application.
Basically I am storing column name in database with their grid name. In next run, I need to read those column names from database and apply changes to the grid dynamically.
Please let me know how I can do this.
I would really appreciate if you/someone could suggest me some way.
Thanks
treeView_1376.zip
AD
Administrator
Syncfusion Team
April 27, 2005 09:40 PM UTC
I made an posibility to persist the column order of the GDBG and I''m using the MappingName for this. If you have only bound columns, that would be one way.
Another way:
// if you don''t have GridBoundColumns defined
for( int i = 1; i < this.gridDataBoundGrid1.Binder.InternalColumns.Count; i++ )
{
MessageBox.Show( this.gridDataBoundGrid1[0, i].Text );
}
// if you have GridBoundColumns defined
for( int i = 1; i < this.gridDataBoundGrid1.GridBoundColumns.Count; i++ )
{
MessageBox.Show( this.gridDataBoundGrid1[0, i].Text );
}
To access the column objects, check the indexer on GDBG.GridBoundColmns or GDBG.Binder.InternalColumns.
Regards,
Thomas
AD
Administrator
Syncfusion Team
April 27, 2005 11:05 PM UTC
Hi,
I have attached a sample here.
No matter which method i use (as suggested by thomas) I always get the following names
As column name
employee_no
employee_name
employee_company_name
employee_dept_name
employee_boss_name
But I wanted to get these names.
gridBoundColumn1
gridBoundColumn2
gridBoundColumn3
gridBoundColumn4
gridBoundColumn5
So that I can use the following code in future
gridBoundColumn1.ReadOnly= true;
gridBoundColumn2.ReadOnly= true;
Otherwise I have to store these names in database as column name
employee_no
employee_name
employee_company_name
employee_dept_name
employee_boss_name
Which i don’t want because what if at run time we attached a new dataset with different
Column names then the following code wouldn''t work
gridDataBoundGrid1.GridBoundColumns["employee_no"].ReadOnly = true;
gridDataBoundGrid1.GridBoundColumns["employee_name"].ReadOnly = true;
But following code would always work
gridBoundColumn1.ReadOnly= true;
gridBoundColumn2.ReadOnly= true;
Please do suggest.
Thanks
sample3_2309.zip
AD
Administrator
Syncfusion Team
April 28, 2005 04:38 AM UTC
Hi,
Check out this code:
FieldInfo[] fields = this.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Instance );
foreach( FieldInfo info in fields )
{
if( info.FieldType == typeof( Syncfusion.Windows.Forms.Grid.GridBoundColumn ))
{
MessageBox.Show( info.Name );
Syncfusion.Windows.Forms.Grid.GridBoundColumn col = this.GetType().InvokeMember(
info.Name, BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetField , null, this, null ) as Syncfusion.Windows.Forms.Grid.GridBoundColumn;
if( col != null )
{
MessageBox.Show( "Column found" );
}
}
}
Regards,
Thomas
AD
Administrator
Syncfusion Team
April 28, 2005 04:06 PM UTC
This works but not the way I want.
It is giving me the name of all the “grdBoudColumn’ in a form. So if there are more than one GDBG attached to aform then it give you all together.
I need to find for each GDBG individually, so that I can hava relationship between GDBG object and its columns in a table.
I tried the following code but it doesn’t work
private void button3_Click(object sender, System.EventArgs e)
{
FieldInfo[] fields = gridDataBoundGrid1.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Instance);
foreach( FieldInfo info in fields )
{
if( info.FieldType == typeof( Syncfusion.Windows.Forms.Grid.GridBoundColumn ))
{
MessageBox.Show( info.Name );
}
}
}
But above code doesn’t work. It does not give me any thing.
Please help me.
AD
Administrator
Syncfusion Team
April 28, 2005 04:17 PM UTC
Please check the documentation of the System.Relfection classes, the code your are providing will never give you the names of the GridBoundColumns, the are stored in the grid.GridBoundColumns collection.
I cannot give you further advices, for me the solution is clear with using the MappingName.
Regards,
Thomas
AD
Administrator
Syncfusion Team
April 28, 2005 04:34 PM UTC
Thanks for all your help.