List of recipes in alphabetical order

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
ladin79
Posts: 19
Joined: Tue Nov 13, 2012 12:25 pm

List of recipes in alphabetical order

Post by ladin79 »

Hi!
Currently I'm using a ListBox to sort the list of recipes using the following code:
void FillList()
{
List<string> myRecipeNames;
myRecipeNames = Globals.Recipe1.FieldNames;

foreach( string i in myRecipeNames)
ListBox1.Items.Add(i);
this.m_AnalogNumeric1.Focus();
}

void Popup_save_constant_Opened(System.Object sender, System.EventArgs e)
{
FillList();
}

void ListBox1_SelectionChanged(System.Object sender, System.EventArgs e)
{
Globals.Tags.Recipe_Name_To_Load.Value = (string) ListBox1.SelectedItem;
}

How can I do the same thing using a DataGrid, so as to be able then to sort the list of recipes in alphabetical order?

Thank you very much!

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: List of recipes in alphabetical order

Post by Edmund »

You could do two things, use a datagrid/listview or sort your list.

Have you tried

Code: Select all

List<string> myRecipeNames;
myRecipeNames = Globals.Recipe1.FieldNames;

myRecipeNames.Sort();
I also have a example of a listview but it´s a bit more complex

I load a List<StopItem> into the list view and the binding is done in the xaml file.

XAML

Code: Select all

 <ListView Foreground="#FF000000" FontFamily="Segoe UI Light" FontSize="18" Name="ListView1" Width="1205.28634361233" Height="395.066079295154" RenderTransformOrigin="0.5,0.5" Visibility="Visible" Panel.ZIndex="18" Canvas.Left="41.2158590308372" Canvas.Top="333.495154185022">
    <ListView.View>
      <GridView>
        <GridViewColumn Width="120" Header="From">
          <GridViewColumn.DisplayMemberBinding>
            <Binding Path="Start_time" />
          </GridViewColumn.DisplayMemberBinding>
        </GridViewColumn>
        <GridViewColumn Width="120" Header="To">
          <GridViewColumn.DisplayMemberBinding>
            <Binding Path="End_time" />
          </GridViewColumn.DisplayMemberBinding>
        </GridViewColumn>
        <GridViewColumn Width="240" Header="Cause">
          <GridViewColumn.DisplayMemberBinding>
            <Binding Path="Cause" />
          </GridViewColumn.DisplayMemberBinding>
        </GridViewColumn>
        <GridViewColumn Width="240" Header="Section">
          <GridViewColumn.DisplayMemberBinding>
            <Binding Path="Section" />
          </GridViewColumn.DisplayMemberBinding>
        </GridViewColumn>
        <GridViewColumn Width="240" Header="Position">
          <GridViewColumn.DisplayMemberBinding>
            <Binding Path="Position" />
          </GridViewColumn.DisplayMemberBinding>
        </GridViewColumn>
        <GridViewColumn Width="240" Header="Sub Position">
          <GridViewColumn.DisplayMemberBinding>
            <Binding Path="Sub_position" />
          </GridViewColumn.DisplayMemberBinding>
        </GridViewColumn>
      </GridView>
    </ListView.View>
  </ListView>
The class being loaded

Code: Select all

/// <summary>
	/// Class representing a stop
	/// </summary>
	public class StopItem
	{
		private string start_time;
		private string end_time;
		private string cause;
		private string section;
		private string position;
		private string sub_position;
		
		public StopItem(string start_time, string end_time, string cause, string section, string position, string sub_position)
		{
			this.start_time = start_time;
			this.end_time = end_time;
			this.cause = cause;
			this.section = section;
			this.position = position;
			this.sub_position = sub_position;
		}
		
		public string Start_time 
		{
			get { return this.start_time;}
		}
		
		public string End_time 
		{
			get { return this.end_time;}
		}
		
		public string Cause 
		{
			get { return this.cause;}
			set { this.cause = value;}
		}
		
		public string Section 
		{
			get { return this.section;}
			set { this.section = value;}
		}
		
		public string Position 
		{
			get { return this.position;}
			set { this.position = value;}	
		}
		
		public string Sub_position 
		{
			get { return this.sub_position;}
			set { this.sub_position = value;}	
		}
	}
And the dataload call

Code: Select all

	// Load data into grid
			ListView1.ItemsSource = Globals.Database_Functions.GetShiftStops();
The function Globals.Database_Functions.GetShiftStops() returns a List of StopItem.

Maybe you can modify it so you can have some use of it...
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

Post Reply