• Using GridEX Control in Unbound Mode [Janus GridEX WinForms Control v3.5 for .NET]

    This tutorial is intended to show you how to use GridEX control in unbound mode using AddItem method to add rows to the control.



    Follow these steps to create a simple form using a GridEX control to display unbound items.



    1) Create a new Visual Basic or C# project using "Windows Application" Template.

    2) Open Form1 that was created when the project was created.

    3) Drop a GridEX control into Form1.

    4) Set BoundMode property in GridEX equal to BoundMode.Unbound

    5) Open GridEX Designer. Click in the "Create Root Table" button.

    6) Add columns to the RootTable.



    To create the columns, follow these steps:



    6.1 - In the GridEX Designer, select Columns collection below the RootTable node and click in the Add button.



    6.2 - Select "Unbound Column" and change the Key of the new column to "Name". Click Next, then Click Finish.



    6.3 - Click Add Button Again. In the "Add Column Wizard", Select "Unbound Column" and change the key of the new Column to "Date". Click Next.



    6.4 - Change EditType property to CalendarCombo. Click Finish.



    6.5 - Once the "Date" column is add, select the column in the designer and change the following properties:



    DataTypeCode = DateTime

    FormatString = d

    DefaultGroupInterval = Date





    7) Add a button to the form. Set its Text = "Add Item". In the click event of the button, use the following code:



    In VB .NET:





    In C# .NET:



    //Add a new row at the end of the list specifying its cell values.

    GridEXRow newRow = this.gridEX1.AddItem();

    //To edit values in cells of a row, call BeginEdit/EndEdit methods

    newRow.BeginEdit();

    newRow.Cells["Name"].Value = "InsertItem";

    newRow.Cells["Date"].Value = DateTime.Now;

    newRow.EndEdit();

    //Move to the new item

    this.gridEX1.MoveTo(newRow);



    8) Add another button. Set its Text = "Insert Item". In the click event of the button, use the following code:



    In VB .NET:





    In C# .NET:



    //Insert the item at the beginning of the list.

    GridEXRow newRow = this.gridEX1.AddItem(0);

    //To edit values in cells of a row, call BeginEdit/EndEdit methods

    newRow.BeginEdit();

    newRow.Cells["Name"].Value = "InsertItem";

    newRow.Cells["Date"].Value = DateTime.Now;

    newRow.EndEdit();

    //Move to the new item

    gridEX1.MoveTo(newRow);



    9) Add another button. Set its Text = "Remove Selected Item". In the click event of the button, use the following code:



    In VB .NET:





    In C# .NET:



    //Get current row

    GridEXRow item = gridEX1.CurrentRow;

    If (item != null && item.RowType == RowType.Record)

    {
    //Delete the row.

    item.Delete();
    }

    else

    {
    MessageBox.Show("Select an item to delete.");
    }



    10) Add another button. Set its Text = "Clear Items". In the click event of the button, use the following code:



    In VB .NET:





    In C# .NET:



    //Clear all items in GridEX

    this.gridEX1.ClearItems();



    11) In the Load event of the form, add some rows to the grid.



    In VB .NET:





    In C# .NET:



    this.gridEX1.AddItem("Item 1", DateTime.Now);

    this.gridEX1.AddItem("Item 2", DateTime.Now);

    this.gridEX1.AddItem("Item 3", DateTime.Now);

    this.gridEX1.AddItem("Item 4", DateTime.Now);

    this.gridEX1.AddItem("Item 5", DateTime.Now);

    this.gridEX1.Row = 0;



    12) Press F5 and run the project.

    Source Of Information : Janus v3.5 Help Files for VS 2008


1 comments:

  1. Bidi says:

    The statement GridEXRow me does not work, tells me that the compiler does not recognize it, you could upload a compilable solution?

Leave a Reply