none
Using Arrays to Display Content RRS feed

  • Question

  • Hi,

    I am using below code to populate item modifiers into an array. The modifier_group_id could be any number from the table but it is unique as it is a primary key, e.g.:

    • 2
    • 17
    • 99
    • 107
    • 214

    I want once the load_item_modifiers is finished to run a code like this:

    private void display_modifiers(int mod_id) {

    next_mod_id = xxxx;

    // Show mod_control with details for mod_id = xxx

    // Next button when clicked will run disaply_modifiers(next_mod_id); }

    mod_control will have a Next button to display the next modifiers..

    How can I pass the next modifier every time to the display the mod for the current as above?

    so when the load_item_modifiers finish in the above example, it will show content for mod 2 and the next button in the content will run display_modifiers(17) ... when user clickes the button it will then display the contents for 17 and the next button will run display_content(99), etc..

    here is the array population code..


    private void load_item_modifiers(int item_id)
    {
        try
        {
            sql_connection = new SqlConnection(serverClass.connectionstring("Savanna", "Savanna", "LocalServer"));
            sql_connection.Open();
    
            sql_command = new SqlCommand("sp_load_item_modifiers", sql_connection);
            sql_command.CommandType = CommandType.StoredProcedure;
            // sql_command.Parameters.AddWithValue("@concept_id", 1).SqlDbType = SqlDbType.Int;
            sql_command.Parameters.AddWithValue("@item_id", item_id).SqlDbType = SqlDbType.Int;
            sql_reader = sql_command.ExecuteReader();
    
            List<int> modifiers = new List<int>();
            int i = 0;
    
            while (sql_reader.Read())
            {
                modifiers.Add(Convert.ToInt32(sql_reader["modifier_group_id"]));
            }
        }
        catch (Exception exp)
        {
            XtraMessageBox.Show(String.Format("Error Loading Modifiers.{0}{1}", Environment.NewLine, exp.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        finally
        {
            if (sql_reader != null) { sql_reader.Close(); sql_reader.Dispose(); }
            if (sql_connection != null) { if (sql_connection.State == ConnectionState.Open) { sql_connection.Close(); sql_connection.Dispose(); } }
        }
    }

    Thanks,

    Jassim


    Tuesday, December 13, 2016 7:26 PM

All replies

  • Hi Jassim,

    According to your title, you may use a loop as following,

    foreach(var item in yourArray)
    {
        Console.WriteLine(item.ToString());
    }

    Also you may want to try something like this:

    yourArray.ToList().ForEach(i => Console.WriteLine(i.ToString()));

    How can I pass the next modifier every time to the display the mod for the current as above?

    Maybe for loop will be suitable for your scenario.

    // Loop over strings.
    	for (int i = 0; i < yourArray.Length; i++)
    	{
    	    string s = yourArray[i];
    	    Console.WriteLine(s);
    	}
    
    	// Loop over strings backwards.
    	for (int i = yourArray.Length - 1; i >= 0; i--)
    	{
    	    string s = yourArray[i];
    	    Console.WriteLine(s);
    	}
    

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 15, 2016 2:29 AM