C# how to map to a photo

Michelle Kamp 41 Reputation points

I am new to C# and need to know how code and map to a student photo. In my example below, when a person selects Student Details for a student, it would go to a student details form. In this form, it would have a photo of the student and other class information.
How do I go about coding that select student to their photo which is located on a local directory, and the photo is named the student id. The student id would be the primary key.

Thank you


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,642 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,634 questions
{count} votes

Accepted answer
  1. Leonardo Zacche 81 Reputation points

    Hi @MichaelHan-MSFT .

    Whenever your user selects (clicks) the "Student Details" button, you will open the "Student_Details" form to show the deails. You need to pass the ID of the student to this form. There are several ways to do this (eg: call a method on the newly instantiated form, pass as parameter to a non-default constructor, pass the form as parameter to a method that you fill it, etc), so it is better to see your code to better help you.

    Once you have the ID, it is easy to build the file name (including the path) of the picture to be displayed as a photo. To actually display depends on the control you are using. Is it a PictureBox? Any other control? The PictureBox seems to me to be easier to use.

    Either way, you have to have the IDs of the students associated to each line of your grid. It seems you already have it (the second column). If so, just use it. If not, you have to store the ID somewhere in the line. It can be a (new) visible column or an invisible column (not visible but available to use it in code). Again, it is easier to help you if we see you code.

    0 comments No comments

0 additional answers

Sort by: Most helpful