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 8295043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:26:44+00:00 2026-06-08T14:26:44+00:00

I have a grid that is being populated through code. This is my implementation:

  • 0

I have a grid that is being populated through code. This is my implementation:

for (int i = 1; i <= 3; i++)
{
     for (int j = 0; j < 3; j++)
     {
          Image oImage = new Image();
          Window.myGrid.Children.Add(oImage);

          oImageSource.UriSource = oImageUri;

          oImage.Source = oImageSource;

          Grid.SetRow(oImage, i);
          Grid.SetColumn(oImage, j);
     }
}

I’m looking for a solution that with it I will be able to do the next:

When someone clicks on the object oImage, which I added as a child, a function will trigger, and the slot’s row and column will be it’s parameters.

So if I have the next grid (each number represents an object that was appended to the grid):

1 | 2 | 3

4 | 5 | 6

7 | 8 | 9

Clicking on 9 will trigger the function func(2, 2) (row’s and column’s index is 2)

  • 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-06-08T14:26:49+00:00Added an answer on June 8, 2026 at 2:26 pm

    You can take advantage of the closure feature of lambda expressions to make this work, though you have to be careful.

    Inside your inner for loop, you do something like this:

    Image oImage = new Image();
    Window.myGrid.Children.Add(oImage);
    
    var row = i;
    var col = j;
    oImage.MouseUp += (sender, args) => func(row, col);
    

    This will attach the specified lambda expression to the MouseUp event for the Image instance, which will call your function with the appropriate values. The lambda expression will close over those variables, even after they leave scope, and it will remember their values.

    The key here is that you need to use locally scoped variables as the parameters. By doing so, you will create a new copy of row and col each pass through the loop. More specifically, you can not use func(i,j) — the lamba will “remember” the last value that i and j had, and will always called func(3,3) on all 9 images.

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

Sidebar

Related Questions

I have a DataGrid that's being populated with the code below, the code below
Let's say I have some grid that looks like this _ _ _ _
I have a DataView that was already populated with data (Verified this to be
I have, in a window, a Grid that contains a RadioButton , a TextBox
I have a draggable that is being dropped on an isometric grid of droppables
I have a grid that has multiple rows. I want to hide/show one of
I have a grid that is dynamically generated based on search criteria. I render
I have a parent grid that contains multiple row definitions, all of which have
I have a grid view that has two simple columns, a report number and
I'm using .NET webforms. I have a grid view that can use Eval(Name) in

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.