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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:19:28+00:00 2026-05-30T23:19:28+00:00

I have 2 partial classes, Window A(frmSchedule) and Window B(frmAddLesson). Window A has a

  • 0

I have 2 partial classes, Window A(frmSchedule) and Window B(frmAddLesson). Window A has a data-bound ListView control in it. Window A opens up Window B, which is designed to create a new Lesson object, and I want to put that lesson data back into Window A. What are some of the ways I can accomplish this? Is there an easy way to use application-scope variables in C#?

I’ve tried deriving both partial classes from a single base class and using that class to funnel the Lesson data back to the 1st window, but I can’t figure it out. 🙁

For more info, I’ve laid out the program here:

I have a main window(fmrSchedule) with a ListView control bound to an ObservableCollection:
(For the sake of simplicity, I’ll pretend the Lesson object has only 1 piece of data that matters)

    <ListView Name="lstLessons" Margin="204,15,192,125" ItemsSource="{Binding Path=LessonList}">
        <ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Time}">Time</GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

In the code:

public partial class frmSchedule : Window
{        
    public frmSchedule()
    {
        InitializeComponent();

        //ListView sample data
        aLesson = new Lesson();
        aLesson.Time = 9;
        m_myLessons.Add(aLesson);
        lstLessons.ItemsSource = LessonList;
    }

    Lesson aLesson;

    private ObservableCollection<Lesson> m_myLessons = new ObservableCollection<Lesson>();
    public ObservableCollection<Lesson> LessonList { get { return m_myLessons; } }

    //Add Lesson
    private void btnAdd_Click(object sender, RoutedEventArgs e)
    {
        //New frmAddLesson window
        frmAddLesson addLesson = new frmAddLesson();
        addLesson.Show();
    }

The btnAdd button control opens a 2nd form(frmAddLesson), which serves to create a new Lesson object to be added to the Lesson list in the main window: (in this case, time is set based on a combobox selection)

public partial class frmAddLesson : Window
{
    public frmAddLesson(System.DateTime? DateTime)
    {
        InitializeComponent();

        dateTime = DateTime;
        radPrivate.IsChecked = true;
    }

    //DateTime from calendar selection
    private DateTime? dateTime;
    //Lesson object
    private Lesson theLesson;

    //ADD LESSON
    private void btnAdd_Click(object sender, RoutedEventArgs e)
    {
        //Create new Lesson object
        theLesson = new Lesson();

        //Set Lesson property
        theLesson.Time = (int)cmbTime.SelectedValue; //Time

        this.Close();
    }
}

The Lesson class:

public class Lesson
{
    public Lesson()
    {
        //Stuff for later
    }

    private int m_Time;

    public int Time { get { return m_Time; } set { m_Time = value; } }
}
  • 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-30T23:19:29+00:00Added an answer on May 30, 2026 at 11:19 pm
    public partial class frmSchedule : Window 
    {       
       ...  
       private void btnAdd_Click(object sender, RoutedEventArgs e)  
       {  
        //New frmAddLesson window  
        frmAddLesson addLesson = new frmAddLesson(this);  
        addLesson.Show();  
       }  
    
       public void AddLesson(Lesson lesson)
       {
         ...
       }
    }
    
    public partial class frmAddLesson : Window    
    {
      public frmAddLesson(frmSchedule schedule)      
      {      
        InitializeComponent();      
    
        this.schedule = schedule;
    
        ...
    
      }    
      frmSchedule schedule;
    
      //ADD LESSON    
      private void btnAdd_Click(object sender, RoutedEventArgs e)    
      {    
        //Create new Lesson object    
        var theLesson = new Lesson();    
    
        //Set Lesson property    
        theLesson.Time = (int)cmbTime.SelectedValue; //Time    
    
        schedule.AddLesson(theLesson);
    
        this.Close();    
      }    
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem. I create two instaces of my classes in main window.
Is it possible to have partial classes across projects. e.g. Project 1 has a
I want to program something in both C# and F#. I have partial classes
I have two pages page1.aspx and page2.aspx, both have code behind with partial classes.
I have: Main Program Class - uses Library A Library A - has partial
I have a WPF dll that contains a number of Window classes and exposes
I have a lot of classes for data-access in one of my projects, but
I have a three nested classes, Show, Season and Episode, where a show has
I have the following classes: using System; using System.Windows.Forms; namespace FastEyeControl { public partial
I have this classes on the same namespace: public partial class BaseForm : Form

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.