Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:46:45+00:00 2026-05-29T19:46:45+00:00

First time poster so sorry if this is too long, but I’ve hit a

  • 0

First time poster so sorry if this is too long, but I’ve hit a wall and don’t know what else to try.

I’m making a Matrices Calculator and doing so with C# and WPF.

I’ve been spending the last hour trying to figure out what’s wrong with my Array Iterator to view and edit the values in a 2D NxN array.

To get a better idea my project so far requires the user to input a size n to make the array. It’ll generate a 2D int array of size NxN of 0’s and start at the default position of (0, 0). From there the user can edit the value going from Left to Right, Top to Bottom editing the whole array.

I have 2 private global ints, one that keeps track of the row position and one that keeps track of the column position and manipulating these numbers to edit that part of the array.

The iterations starts off fine going (0, 0) > (0, 1); however instead of going from (0,1) > (0,2) like it should it jumps to (1, 1). I’ve gone countless times over my if logic and can’t find where I’m doing it wrong though.

I have yet to test the traversing back right to left, bottom to top yet but since it’s logic is nearly identical I’m assuming it’ll have the same problems I’m currently having.

Many thanks if someone could point me where in my logic it’s flawed so I can move onto coding up the other parts.

My code is as follows:

private int[,] matrix; //Matrix currently being edited
private int row; //keeps track of current row position and set to 0 when matrix is made
private int col; //Keeps track of current column position and set to 0 when matrix is made

private void previousPos_Click(object sender, RoutedEventArgs e)
    {
        Console.WriteLine("row " + row + "\r\n col " + col);
        if (row < 0 && col < 0)
        {
            textBlock1.Text = "No previous values to edit";
            row = 0;
            col = 0;
            positionDisplay.Text = "" + col + ", " + row;
        }
        else if (row < 0 && col < 3)
        {
            setValue(row, col, valueDisplay.Text);
            row = 2;
            col -= 1;
            displayMatrix(matrix);
            positionDisplay.Text = "" + col + ", " + row;
        }
        else
        {
            setValue(row, col, valueDisplay.Text);
            row -= 1;
            displayMatrix(matrix);
            positionDisplay.Text = "" + col + ", " + row;
        }
    }

private void nextPos_Click(object sender, RoutedEventArgs e)
    {
        Console.WriteLine("row "+row+"\r\ncol "+col);
        if (row >= matrix.GetLength(0) && col >= matrix.GetLength(1))
        {
            textBlock1.Text = "No more values to edit";
            row = matrix.GetLength(0) - 1;
            col = matrix.GetLength(1) - 1;
            positionDisplay.Text = "" + col + ", " + row;
        }
        else if (row >= matrix.GetLength(0) && col < matrix.GetLength(1))
        {
            setValue(row, col, valueDisplay.Text);
            col += 1;
            row = 0;
            displayMatrix(matrix);
            positionDisplay.Text = "" + col + ", " + row;
        }
        else
        {
            setValue(row, col, valueDisplay.Text);
            row += 1;
            displayMatrix(matrix);
            positionDisplay.Text = "" + col + ", " + row;
        }
    }

    public void setValue(int curRow, int curCol, string value)
    {
        col = curRow;
        row = curCol;
        try
        {
            matrix[row, col] = int.Parse(value);   
        }
        catch(Exception)
        {
            string messageBoxText = "Please input a valid number";
            string caption = "Warning";
            MessageBoxButton button = MessageBoxButton.OK;
            MessageBoxImage icon = MessageBoxImage.Warning;
            MessageBox.Show(messageBoxText, caption, button, icon);
        }
    }

Edit: Fixed a typo I saw and willing to post more/rest of code on request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:46:47+00:00Added an answer on May 29, 2026 at 7:46 pm

    You have this error in setValue():

     col = curRow;
     row = curCol;
    

    Column equals row? Typo!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First time poster, long time reader. I've been having a problem with figuring this
I'm a long time reader first time poster, glad to start participating in this
Hey Everyone. I'm a first time poster, but I've browsed this site a number
This is a pretty simple question; first time poster and long time looker. Here
Long time user, first time poster. I've found similar questions/answers, typically involving subqueries, but
Hy everyone, Long time reader, first time poster. This sounds like it should be
first time poster, long time reader so be gentle with me :) See the
Long time reader, first time poster. Any help is greatly appreciated. I have crafted
I'm a long running fan of stackoverflow, first time poster. I'd love to see
first time poster. Please be gentle. This topic may be similar to several other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.