0

hello I've been struggling in this part of my code in which I need to instantiate a window where if the student record is found in my list when I search it, it will open another window of it so that it can be edited.

Scenario is for example like this. my list has a student named : James and Roger. when I input Roger in the textbox and search for it, another window will pop up and displays all of Roger's details. how can I do that? I tried it but everytime I searched Roger's name, James' details pop up ( cs it was the first detail added in the list.) I'll be waiting for the response. Thanks in advance. Here is my code.

    public partial class EditStudent : Window
{

    List<Data> editstudentdata = new List<Data>();


    public EditStudent(List<Data>studentdata)
    {
        InitializeComponent();
        editstudentdata = studentdata;
        DataContext = studentdata;

    }
    void searchbtn(object sender, RoutedEventArgs e)
    {
        for ( int i = 0; i < editstudentdata.Count ; i++ )
        {
            if ( editstudentdata[i].idnum == searchidnumbox.Text)
            {

                ( What should I input here? )

            }
            if ( editstudentdata[i].idnum != searchidnumbox.Text)
            {
                resultblock.Text = "Data not found!!!" ;
            }
        }

    }
porogamiii
  • 33
  • 6

1 Answers1

1

On Window, make a property of Data class and whenever your condition matched, initialized your window and before call Window.Show(), initialize that property.

Something like this,

public partial class Window{
    Data student;
    Window(){
        // load properties of student to some textboxex, 
        //   so when this window will open your data is pre loaded.
    }
}

In your logic, you can do something like this,

       for ( int i = 0; i < editstudentdata.Count ; i++ )
        {
            if ( editstudentdata[i].idnum == searchidnumbox.Text)
            {
                    Window newWindow = new Window();
                    newWindow.student = editstudentdata[i];
                    this.Hide();
                    newWindow.show();
            }
            if ( editstudentdata[i].idnum != searchidnumbox.Text)
            {
                resultblock.Text = "Data not found!!!" ;
            }
        }

Sorry it's not a proper coding, just a pseudocode type. Hope it helps you.

Safwan Shaikh
  • 546
  • 2
  • 9
  • thanks bro. your code somewhat triggers some ideas for me and yes its working now. thanks a lot – porogamiii Aug 07 '18 at 08:10
  • Your most Welcome..It seems you are new geek here so If you find any of the useful answer on Stack Overflow community, you can up vote it :) Thank you. – Safwan Shaikh Aug 07 '18 at 08:11