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

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15749 |

    Hi,
    Can I access the contents of a datasource of a Xceed Grid.Gridcontrol ?
    Does anyone have a VBscript for it ?

    And also what is the code to access or datarows of a Xceed.Grid.Gridcontrol.

    Thanks
    Gopal

    Imported from legacy forums. Posted by gopal (had 6777 views)

    Xceed Support
    Member
    Post count: 5658

    Here is some VB.NET on how to access the DataSource and a DataRow (in this snippet, the first cell of the first row).

    <code>
    Dim dataSource As Object = gridControl1.DataSource

    Dim bs As BindingSource = DirectCast(dataSource, BindingSource)

    Dim value As Integer = CInt(gridControl1.DataRows(0).Cells(0).Value)
    </code>

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks Charles.

    When I paste your code in my class library (VB DLL), then BindingSource is not recognised.
    Thereby my vb.net project is not compiling.

    Secondly, can I pass gridcontrol1 object to DLL.
    Will this code work in my class library DLL project.

    Please let me know.

    Thanks
    Gopal

    Imported from legacy forums. Posted by gopal (had 371 views)

    User (Old forums)
    Member
    Post count: 23064

    charles,

    Dim value As Integer = CInt(gridControl1.DataRows(0).Cells(0).Value)

    In your code you are not making use of bs anywhere. Please let me if this is correct ?

    And which .dll is required to be reference for Bindingsource ?

    Rgds
    Gopal

    Imported from legacy forums. Posted by gopal (had 338 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    Thanks charles for your code.

    I need the code the other way round i.e., I want to pass a GridControl object, or Datarows object or Datasource object to a DLL. And then get the values from the GridControl, Datarows or Datasource and pass it back to QTP.

    I am facing problem in QTP. QTP is not able to recognise Xceed Grid as a Grid. Hence I am passing it as a OBJECT to a DLL file and the get the values from DLL.

    Is it possible for you to give me the C# code which gets the values from grid which is passed as a object ?

    Also do you know how I can access this .net dll in QTP and the code in QTP ?
    I am using DOTnetFactory.CreateInstance command in QTP to access the dll.

    Please let me know.
    Thanks for your prompt reply.

    Rgds
    Gopal

    Imported from legacy forums. Posted by gopal (had 373 views)

    Xceed Support
    Member
    Post count: 5658

    Since we do not own QTP or are able to test the code with it, I not sure what you are missing.

    With the same casting I used in the previous code, I was able to call the Grid through a .dll that was, itself, calling his grid through an other .dll.

    In the .dll, I just return the Grid as an object and cast it back to a GridControl at reception.

    Here is how I called the .dll in my pass-through .dll class library:

    <code>
    public object ReturnGridThroughDLL()
    {
    ClassLibraryForum9845.Class1 objGridThroughGrid = new ClassLibraryForum9845.Class1();

    GridControl grid = (GridControl) objGridThroughGrid.functionGrid();

    return (object) grid;
    }
    </code>

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

    User (Old forums)
    Member
    Post count: 23064

    Hi Guys,

    I hope this will help you all who are working Xceed grid with QTP.
    This works.

    Set accSumGrid = swfwindow(“CMD View”).SwfObject(“grid”).Object
    Set myDs = accSumGrid.DataSource

    For i= 0 to (myDs.Rows.Count -1)
    For j = 0 to 3
    msgbox myDs.Rows.Item(i).Item(j)
    Next
    Next

    Have fun.
    Rgds
    Gopal

    Imported from legacy forums. Posted by gopal (had 6184 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Gopal,

    When I run the above Code I get an Error message ”  Object doesn’t support this property or method : ‘myDs.Rows’

     Please let me know if you already have got the solution for the same.

    Regards,
    Rajesh

    Imported from legacy forums. Posted by Rajesh (had 1257 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.