Home - Forums-.NET - FlyGrid.Net (Windows Forms) - C#: Additional samples

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

C#: Additional samples
Link Posted: 28-Feb-2006 16:51
This c# sample shows how to dynamically determine node's children.
Initially each node in this sample returns HasChildren = true, but after attempting to expand node starts to returning real HasChildren value, as children is determined in the process of node expanding.
Link Posted: 01-Mar-2006 16:50
This c# sample shows how to bind to list of objects and edit their properties in the FlyGrid.Net.
This sample gets an array of properties of Column type, adds columns with property names and binds to the array of these columns to edit their properties.
Link Posted: 10-Mar-2006 05:59
This c# code snippet shows how to disable scrollbars in the nested grids:

//FlyGrid initialization procedure
private void InitGrid(FlyGrid flyGrid)
{
  //....
  //connect to the NodeExpandChange event handler
  flyGrid.NodeExpandChange += new NodeHandler(flyGrid_NodeExpandChange);
}
// NodeExpandChange event handler
private void flyGrid_NodeExpandChange(object sender, NodeBase node)
{
   INestedGridNode nested = node as INestedGridNode;
   if (nested != null && node.Expanded)
   {
     FlyGridViewPort port = nested.NestedInternal;
     port.VScrollBarEnabled = false;
   }
}
Link Posted: 16-Mar-2006 05:12
This C# sample shows how to use FlyGrid.RightClickNode, how to select node on right click on the node and how to use selected by right mouse button nodes in the context menus.
Link Posted: 16-Mar-2006 07:15
This C# sample demonstrates FlyGrid performance in virtual mode, usage AutoHeightMemoColumn and virtual data sources/feeds usage to create dynamically updated contents.
Link Posted: 30-Mar-2006 15:21
This C# sample shows three ways of node addition relating to the verious ColumnFitMode modes of columns.
Link Posted: 30-May-2006 10:57
This C# code shows how to create ButtonColumn with data bound images:

[C#]
public class ButtonColumnWithBoundImages : ButtonColumn
{
   public ButtonColumnWithBoundImages() : base(){}
   public ButtonColumnWithBoundImages(string name) : base(name){}
   public ButtonColumnWithBoundImages(string name, string fieldName) : base(name, fieldName){}
   private string imageField = string.Empty;
   [DefaultValue("")]
   public string ImageField
   {
     get {return imageField;}
     set
     {
       if (imageField != value)
       {
         imageField = value;
         base.OnChanged(InvalidationMode.ColumnWithoutHeader, false);
       }
     }
   }
   protected override Image GetButtonImage(NodeBase node)
   {
     if (ImageField != null && ImageField != string.Empty)
     {
       DataRowView dr = node.Value as DataRowView;
       if (dr != null)
       {
         byte[] arr = dr[ImageField] as byte[];
         if (arr != null)
         {
           Image img = Image.FromStream(new System.IO.MemoryStream(arr));
           if (img != null)
             return img;
         }
       }
     }
     return base.GetButtonImage(node);
   }
}
Link Posted: 06-Jun-2006 08:23
This c# code snippet helps to return array of checked nodes:

[c#]
public static NodeBase[] GetCheckedNodes(NodeCollection nodes, bool includeChildren)
{
   ArrayList al = new ArrayList();
   foreach(NodeBase node in nodes)
   {
     if (node.Checked)
       al.Add(node);
     if (includeChildren && node.HasChildren)
       al.AddRange(GetCheckedNodes(node.Items, includeChildren));
   }
   return al.ToArray(typeof(NodeBase)) as NodeBase[];
}

usage example:

[c#]
public NodeBase[] GetCheckedNodes(FlyGrid flyGrid)
{
   return GetCheckedNodes(flyGrid.Rows.Items, true);
}
Link Posted: 27-Jun-2006 07:22
This sample shows how to bind checkboxes in HierachyColumn:
[c#]
using NineRays.Windows.Forms;
using NineRays.Windows.Forms.Data;
using NineRays.Windows.Forms.Grids;
using NineRays.Windows.Drawing;
//....
private void Form1_Load(object sender, System.EventArgs e)
{
  InitFlyGrid(flyGrid);
}

public class BoundCheckBoxColumn : HierachyColumn
{
  public BoundCheckBoxColumn(string name) : base(name){}          
  public BoundCheckBoxColumn(string name, string fieldName) : base(name, fieldName){}
  private string checkBoxFieldName = string.Empty;
  [DefaultValue(\"\")]
  public string CheckBoxFieldName
  {
    get
    {
      return checkBoxFieldName;
    }
    set
    {
      if (checkBoxFieldName != value)
      {
        checkBoxFieldName = value;
        base.OnChanged(InvalidationMode.FullColumn, false);
      }
    }
  }
  
  public override void OnCheckBoxClick(FlyGrid flyGrid, NodeBase node)
  {
    if (CheckBoxesReadOnly && CheckBoxFieldName != string.Empty)
    {
      CheckBoxState cbs = GetCheckBoxstate(node);
      DataRowView drv = node.Value as DataRowView;
      if (drv != null)
      {
        if ((cbs & CheckBoxState.Checked) != 0)
          cbs &= ~CheckBoxState.Checked;
        else
          cbs |= CheckBoxState.Checked;
      
        if ((cbs & CheckBoxState.Grayed) != 0)
          cbs &= ~CheckBoxState.Grayed;

        drv[CheckBoxFieldName] = cbs;
      }
    }
    else
    {
      base.OnCheckBoxClick(flyGrid, node);
    }
  }

  protected override CheckBoxState GetCheckBoxstate(NodeBase node)
  {
    if (CheckBoxFieldName != string.Empty)
    {
      DataRowView drv = node.Value as DataRowView;
      if (drv != null)
      {
        object cellvalue = drv[CheckBoxFieldName];
        return cellvalue != null && cellvalue != DBNull.Value ?
          (CheckBoxState)cellvalue :
          CheckBoxState.None;            
      }
    }
    return base.GetCheckBoxstate (node);
  }      
}

private void InitFlyGrid(FlyGrid flyGrid)
{
  flyGrid.BeginInit();
  try
  {
    BoundCheckBoxColumn boundCheckBoxColumn = new BoundCheckBoxColumn(\"Value\");
    //setup column
    boundCheckBoxColumn.CheckBoxFieldName = \"CheckBoxValue\";
    boundCheckBoxColumn.ShowCheckBoxes = true;
    //fit to width
    boundCheckBoxColumn.FitMode = ColumnFitMode.Spring;        
    flyGrid.Columns.Options |= ColumnsOptions.FitToWidth;
    //hide AddNewRow row
    flyGrid.Rows.Options &= ~ RowsOptions.ShowAddNewRow;
    //add column
    flyGrid.Columns.Items.Add(boundCheckBoxColumn);
    //create and setup datatable
    DataTable dt = new DataTable(\"Data\");
    DataColumn dc = new DataColumn(\"Value\", typeof(string));
    DataColumn dcb = new DataColumn(\"CheckBoxValue\", typeof(ButtonState));
    dt.Columns.Add(dc);
    dt.Columns.Add(dcb);
    //fill data
    for(int i=0; i < 10; i++)
    {
      object[] rowdata =
          {
            \"new row\" + i,
            i % 2 == 0 ? CheckBoxState.Checked : CheckBoxState.Checked | CheckBoxState.Grayed
          };
      dt.Rows.Add(rowdata);
    }
    flyGrid.Rows.DataSource = dt;
  }
  finally
  {
    flyGrid.EndInit();
  }
}
Link Posted: 17-Jul-2006 23:32
This sample shows how to bind array of objects to column overriden from LookupListColumn.