148 lines
3.8 KiB
C#
148 lines
3.8 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="ListPickerItemListModel.cs" company="BTU/IIT">
|
|
// Company copyright tag.List
|
|
// </copyright>
|
|
// <author>stubbfel</author>
|
|
// <sience>25.07.2013</sience>
|
|
//----------------------------------------------------------------------
|
|
namespace CampusAppWPortalLib8.Model.Utility
|
|
{
|
|
using System.Collections.Generic;
|
|
|
|
/// <summary>
|
|
/// Class for a List of ListPickerItems
|
|
/// </summary>
|
|
public class ListPickerItemListModel
|
|
{
|
|
#region Members
|
|
|
|
/// <summary>
|
|
/// reference of the itemList
|
|
/// </summary>
|
|
private List<ListPickerItemModel> list;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ListPickerItemListModel" /> class.
|
|
/// </summary>
|
|
public ListPickerItemListModel()
|
|
{
|
|
this.list = new List<ListPickerItemModel>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary>
|
|
/// Gets or sets the ItemList
|
|
/// </summary>
|
|
public List<ListPickerItemModel> List
|
|
{
|
|
get
|
|
{
|
|
return this.list;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (value != this.list)
|
|
{
|
|
this.list = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
#region public
|
|
|
|
/// <summary>
|
|
/// Method return a the Index of an item which has a certain value
|
|
/// </summary>
|
|
/// <param name="value">a certain value</param>
|
|
/// <returns>return index of value or default(0)</returns>
|
|
public virtual int GetIndexOrDefault(string value)
|
|
{
|
|
int index = 0;
|
|
int i = 0;
|
|
foreach (ListPickerItemModel item in this.list)
|
|
{
|
|
if (item.Value.Equals(value))
|
|
{
|
|
index = i;
|
|
break;
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
/// <summary>
|
|
/// add an new item to the list
|
|
/// </summary>
|
|
/// <param name="value">value of the item</param>
|
|
/// <param name="text">text of the item</param>
|
|
public void AddItem(string value, string text)
|
|
{
|
|
this.AddItem(new ListPickerItemModel(value, text));
|
|
}
|
|
|
|
/// <summary>
|
|
/// add an new item to the list
|
|
/// </summary>
|
|
/// <param name="item">new item of the list</param>
|
|
public void AddItem(ListPickerItemModel item)
|
|
{
|
|
this.list.Add(item);
|
|
}
|
|
|
|
/// <summary>
|
|
/// remove an item
|
|
/// </summary>
|
|
/// <param name="value">value of the item</param>
|
|
/// <param name="text">text of the item</param>
|
|
/// <returns>true if removing was successful, otherwise false</returns>
|
|
public bool RemoveItem(string value, string text)
|
|
{
|
|
return this.RemoveItem(new ListPickerItemModel(value, text));
|
|
}
|
|
|
|
/// <summary>
|
|
/// remove an item
|
|
/// </summary>
|
|
/// <param name="item">item which has to be remove</param>
|
|
/// <returns>true if removing was successful, otherwise false</returns>
|
|
public bool RemoveItem(ListPickerItemModel item)
|
|
{
|
|
return this.list.Remove(item);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region protected
|
|
|
|
/// <summary>
|
|
/// Method load an default list
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// load an empty list
|
|
/// </remarks>
|
|
protected virtual void LoadList()
|
|
{
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|