Home Forums WinForms controls Xceed Grid for WinForms Access contents Datasource of Xceed.Grid.GridControl Reply To: Access contents Datasource of Xceed.Grid.GridControl

Xceed Support
Member
Post count: 5658

I just test it with a “class library” and it works. However, you need to use the same type of DataSource through all your process. For example, if you use a DataTable in the class library’s DataSource, you need to use a DataTable when you call the class library. And yes, you can pass a GridControl through a class library.

For the code I wrote, I was just answering your question without necessarily making any sens between the lines.

Here is some code I created to return a class library that returns a Grid and the DataSource (a DataTable in this case):

<code>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Xceed.Grid;
using Xceed.Grid.Editors;
using Xceed.Grid.Viewers;
using Xceed.Grid.Controls;
using Xceed.Grid.Collections;
using Xceed.Grid.Exporting;
using Xceed.Editors;
using Xceed.Editors.Collections;
using Xceed.UI;
using Xceed.Utils;
using Xceed.Utils.Collections;
using Xceed.Validation;
using System.Data;

namespace ClassLibraryForum9845
{
public class Class1
{
private GridControl gridControl1;

public GridControl functionGrid()
{
gridControl1 = new GridControl();

DataTable dt = new DataTable();
DataColumn dcId = new DataColumn();
dcId.ColumnName = “ComplexId”;
dcId.DataType = System.Type.GetType( “System.Int64” );
dt.Columns.Add( dcId );

DataColumn dcName = new DataColumn();
dcName.ColumnName = “ComplexName”;
dcName.DataType = System.Type.GetType( “System.String” );
dt.Columns.Add( dcName );

for( int i = 0; i < 100; i++ )
{
System.Data.DataRow row = dt.NewRow();
row[ “ComplexId” ] = i;
row[ “ComplexName” ] = i.ToString()+”%”;
dt.Rows.Add( row );
}
gridControl1.FixedHeaderRows.Add( new ColumnManagerRow() );
gridControl1.DataSource = dt;

return gridControl1;
}

public DataTable getDataTable()
{
return (DataTable) gridControl1.DataSource;
}
}
}
</code>

And here is the code I used to call this class library (in an other project after including a reference to the class library):

<code>¨
private void Form1_Load( object sender, EventArgs e )
{
ClassLibraryForum9845.Class1 objGrid = new Class1();

Xceed.Grid.GridControl grid = objGrid.functionGrid();

DataTable table = objGrid.getDataTable();

this.Controls.Add( grid );
}
</code>

Imported from legacy forums. Posted by CharlesB (had 362 views)