Code: Select all
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using System.Linq;
using System.Collections.Generic;
using Neo.ApplicationFramework.Common.Dynamics;
using System.Reflection;
public partial class Component
{
/// <summary>
/// Populates a Touch List Box HMI control with the items from the provided enumerable
/// </summary>
/// <param name="listbox">The list box to populate. Only the Touch version.</param>
/// <param name="item">The items to populate the listbox with.</param>
/// <returns>The binding list used to populate the list box. This object supports operations such as sort.</returns>
public StringIntervalListCF PopulateTouchListBox(Controls.Script.TouchListBoxAdapter listbox, IEnumerable<string> items)
{
// The HMI listbox is just an adapter. We need the adapted object to populate it.
var lb = listbox.AdaptedObject as Controls.TouchListBox.TouchListBoxHost;
// Instantiate the list that will be used to populate the list box with.
var lst = new StringIntervalListCF();
// Itterate all the items in the provided enumerable.
foreach (var row in items.Select((item, i) => new { item, i }))
{
lst.Add(new BindableStringIntervalCF
{
Start = row.i,
End = row.i,
Value = row.item
});
}
// Now set the list box datasource to the generated binding list.
lb.DataSource = lst;
lb.Texts = new System.ComponentModel.BindingList<string>(lst.Select(b => b.Value).ToList());
// Return the list for further operations, such as sort.
return lst;
}
/// <summary>
/// Get the currently selected item from a Touch List Box HMI control.
/// </summary>
/// <param name="listbox">The listbox to get the current item from. Only touch versions.</param>
/// <returns>The currently selected item.</returns>
public string GetSelectedValue(Controls.Script.TouchListBoxAdapter listbox)
{
// Get the property info for the hosted controls.
var hostedControlsPi = listbox.RescoObject.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(p => p.Name == "HostedControl");
// Itterate all the properties found named 'HostedControl'.
foreach (var c in hostedControlsPi)
{
// Get the value of the current control and cast it to the IValueSelector type.
var hostedControl = c.GetValue(listbox.RescoObject) as IValueSelector;
// Check that the cast was successfull and return the selected item value.
if (hostedControl != null)
return ((BindableStringIntervalCF)hostedControl.SelectedItem).Value;
}
return null;
}
}
}