/ Home / HowTo / LJCDataGrid

This example uses the DataAccess code.


Adding Data to an LJCDataGrid

// Retrieves the list rows into a LJCDataGrid Grid.
private void DataRetrieveDataGrid()
{
  // Get the data.
  DataTable dataTable = mPersonManager.GetDataTable();

  // Add the grid rows.
  foreach (DataRow dataRow in dataTable.Rows)
  {
    // Add a new LJCGridRow object.
    LJCGridRow gridRow = PersonGrid.LJCRowAdd();

    // Add the Data Values to the Grid Row.
    foreach (DataColumn dataColumn in dataTable.Columns)
    {
      // Set the Cell value.
      // The DataColumn name is the same as the Grid Column name.
      string columnName = dataColumn.ColumnName;
      gridRow.LJCSetCellText(columnName, dataRow[columnName]);
    }
  }
}

Using Data Object Mapping

using System;

namespace PersonDAL
{
  // The Person table Data Object.
  public class Person
  {
    #region Data Methods

    public override string ToString()
    {
      return string.Format("{0}-{1}", ID, Name);
    }
    #endregion

    #region Data Properties

    // Gets or sets the ID value.
    public int ID { get; set; }

    // Gets or sets the Name value.
    public string Name { get; set; }

    // Gets or sets the PrincipleFlag value.
    public bool PrincipleFlag { get; set; }
    #endregion
  }
}
using System;
using System.Collections.Generic;

namespace PersonDAL
{
  // Represents a collection of Person objects.
  public class Persons : List
  {
  }
}
#region Retrieve/Load Methods

/// <summary>Loads a collection of data records.</summary>;
public Person Load()
{
  PersonTests retValue = null;

  DataTable dataTable = GetDataTable();
  retValue = CreatePersons(dataTable);
  return retValue;
}
#endregion
// Retrieves the list rows into an LJCDataGrid using a Data Object.
private void DataRetrievePerson()
{
  // Get the Data Object Collection.
  Persons persons = mPersonManager.Load();

  foreach (Person person in persons)
  {
    // Add a new LJCGridRow object.
    LJCGridRow gridRow = PersonGrid.LJCRowAdd();

    // Add the Data Values to the Grid Row.
    // The DataObject Property name is used as the Grid Column name.
    PersonGrid.LJCRowSetValues(gridRow, person);

    // Set hidden row values.
    gridRow.LJCSetInt("ID", person.ID);
  }
}

/ Home / HowTo / LJCDataGrid

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.