将从一种形式选择的日期显示到另一种形式

本文关键字:日期 显示 另一种 选择 一种 | 更新日期: 2023-09-27 18:04:14

我想在使用monthcalendar控件的另一种形式中显示所选择的日期。这是我的代码。

private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
    {            
        ActivityScheduler frm1 = new ActivityScheduler();
        frm1.Show();
    } 
private void ActivityScheduler_Load(object sender, EventArgs e)
    {
        if (con.State == ConnectionState.Open) { con.Close(); }
        con.Open();
        RemainderPopUp frm = new RemainderPopUp();
        string s = "select * from [Activity_Scheduler]";
        SqlCommand sCmd = new SqlCommand(s, con);
        SqlDataAdapter da = new SqlDataAdapter(sCmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "[Activity_Scheduler]");
        datagridActivityScheduler.DataSource = ds.Tables[0];
        datagridActivityScheduler.AllowUserToAddRows = true;
        DataTable dt = new DataTable();
        dt = ds.Tables["Activity_Scheduler"];
        if (dt == null)
        {
            datagridActivityScheduler.Rows[0].Cells[3].Value = frm.monthCalendar1.SelectionRange.Start.ToShortDateString();
            MessageBox.Show(datagridActivityScheduler.Rows[0].Cells[3].Value.ToString());
        }
        con.Close();
    }               

在messagebox中显示正确的值,但是在datagridview中没有显示正确的值…谁来帮帮我…

将从一种形式选择的日期显示到另一种形式

试试下面的代码:

 form_load()
 {
 private string myDate="1999/12/12";
    // Declare a Date property of type string:
    public string Name
    {
        get 
        {
           return myDate; 
        }
        set 
        {
           myName = value; 
        }
 }
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{            
    ActivityScheduler frm1 = new ActivityScheduler();
    ActivityScheduler.myDate = frm.monthCalendar1.SelectionRange.Start.ToShortDateString()
    frm1.Show();
} 

现在你可以得到其他形式的日期:

string myDate = frm1.myDate();