• Using GridEX Control as a Checked List [Janus GridEX WinForms Control v3.5 for .NET]

    This tutorial is intended to show you how to use GridEX control as a checked list control with a column acting as selector and the use of the GetCheckedRows method to retrieve an array containing the GridEXRow objects that are checked.



    Follow these steps to create a simple form using a GridEX control as a checked list.



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

    2) Drop a GridEX control into Form1.

    3) In the GridEX Designer dialog, select the GridEX control node and click in the "Create Root Table" button.

    4) Select the Columns node under RootTable node and start the columns the control will present. In this tutorial we created 4 columns. The columns we created and the properties are listed below:



    4.1) From:



    Add Column Wizard:



    Step 1:

    "Selector Column"

    UseHeaderSelector = True



    4.2) Icon:



    Add Column Wizard:



    Step 1:

    "Unbound Column"

    BoundMode: UnboundFetch

    Key = "Icon"



    Step 2:

    Caption = ""

    ColumnType = Image

    EditType = NoEdit



    After finishing the wizard, set these properties:



    AllowSize = False

    ImageIndex = 0

    Selectable = False

    Width = 20



    4.3) From:



    Add Column Wizard:



    Step 1:

    "Bound Column"

    DataMember = "From"



    Step 2:

    Caption = "From"

    ColumnType = Text

    EditType = NoEdit



    After finishing the wizard, set these properties:

    Selectable = False


    4.4) Subject:

    Add Column Wizard:



    Step 1:

    "Bound Column"

    DataMember = "Subject"



    Step 2:

    Caption = "Subject"

    ColumnType = Text

    EditType = NoEdit



    After finishing the wizard, set these properties:

    Selectable = False



    4.5) Date:

    Add Column Wizard:



    Step 1:

    "Bound Column"

    DataMember = "Date"



    Step 2:

    Caption = "Date"

    ColumnType = Text

    EditType = NoEdit



    After finishing the wizard, set these properties:

    Selectable = False







    5) In the Load event of the Form, Call the BindGridEXControl procedure that creates the dataset and binds the control to it:



    In VB .Net:



    Private Sub BindGridEXControl()

    Dim ds As New DataSet()

    Dim table As New DataTable("Messages")

    table.Columns.Add(New DataColumn("From", Type.GetType("System.String")))

    table.Columns.Add(New DataColumn("Subject", Type.GetType("System.String")))

    table.Columns.Add(New DataColumn("Date", Type.GetType("System.DateTime")))

    ds.Tables.Add(table)

    table.Rows.Add(New Object() {"john@mail.com", "Greetings", New DateTime(2002, 2, 5)})

    table.Rows.Add(New Object() {"jenny@mail.com", "Invitation", New DateTime(2002, 2, 7)})

    table.Rows.Add(New Object() {"chris@mail.com", "A question", New DateTime(2002, 2, 10)})

    table.Rows.Add(New Object() {"ana@mail.com", "How are you?", New DateTime(2002, 2, 12)})

    table.Rows.Add(New Object() {"katherine@mail.com", "Greetings", New DateTime(2002, 2, 14)})

    table.Rows.Add(New Object() {"bill@mail.com", "Hi", New DateTime(2002, 2, 18)})

    table.Rows.Add(New Object() {"ronald@mail.com", "No Subject", New DateTime(2002, 2, 20)})

    Me.GridEX1.SetDataBinding(ds, "Messages")

    End Sub



    In C# .Net:



    private void BindGridEXControl()
    {
    DataSet ds = new DataSet();

    DataTable table = new DataTable("Messages");

    table.Columns.Add(new DataColumn("From", typeof(string)));

    table.Columns.Add(new DataColumn("Subject", typeof(string)));

    table.Columns.Add(new DataColumn("Date", typeof(DateTime)));

    ds.Tables.Add(table);

    table.Rows.Add(new Object[] {"john@mail.com", Greetings", new DateTime(2002, 2, 5)});

    table.Rows.Add(new Object[] {"jenny@mail.com", "Invitation", new DateTime(2002, 2, 7)});

    table.Rows.Add(new Object[] {"chris@mail.com", "A question", new DateTime(2002, 2, 10)});

    table.Rows.Add(new Object[] {"ana@mail.com", "How are you?", new DateTime(2002, 2, 12)});

    table.Rows.Add(new Object[] {"katherine@mail.com", "Greetings", new DateTime(2002, 2, 14)});

    table.Rows.Add(new Object[] {"bill@mail.com", "Hi", new DateTime(2002, 2, 18)});

    table.Rows.Add(new Object[] {"ronald@mail.com", "No Subject", new DateTime(2002, 2, 20)});

    this.GridEX1.SetDataBinding(ds, "Messages");

    }





    6) Add a button to the form and set its Text property to "Delete". In the Click event of the delete button, get an array containing the checked rows and delete them from its table.



    In VB .Net:





    Dim checkedRows() As Janus.Windows.GridEX.GridEXRow

    'get an array with all the rows that the user checked.

    checkedRows = Me.GridEX1.GetCheckedRows()

    'if the user didn't check any row, you will get an empty array

    If checkedRows.Length = 0 Then

    MessageBox.Show("Select at least 1 message to be deleted.")

    Else

    Dim message As String

    message = String.Format("You are about to delete {0} message(s)." _

    & vbCrLf & "Do you want to continue?", checkedRows.Length)

    If MessageBox.Show(message, "Janus Tutorial", MessageBoxButtons.YesNo) = DialogResult.Yes Then

    Dim row As Janus.Windows.GridEX.GridEXRow

    For Each row In checkedRows
    CType(row.DataRow, DataRowView).Delete()
    Next

    End If

    End If



    In C# .Net:



    Janus.Windows.GridEX.GridEXRow[] checkedRows;

    //get an array with all the rows that the user checked.

    checkedRows = this.GridEX1.GetCheckedRows();

    //if the user didn't check any row, you will get an empty array

    if(checkedRows.Length==0)

    {
    MessageBox.Show("Select at least 1 message to be deleted.");
    }

    else

    {
    string message;

    message = String.Format("You are about to delete {0} message(s)." +

    "\n\rDo you want to continue?", checkedRows.Length);

    if(MessageBox.Show(message, "Janus Tutorial", MessageBoxButtons.YesNo) == DialogResult.Yes)

    {

    foreach(Janus.Windows.GridEX.GridEXRow row in checkedRows)

    {

    ((DataRowView)row.DataRow).Delete();

    }

    }

    }



    7) Press F5 and run the project.

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


Leave a Reply