【问题标题】:display the value of datagridview in the textboxes present in another form在以另一种形式存在的文本框中显示 datagridview 的值
【发布时间】:2013-07-31 07:57:37
【问题描述】:

我们如何以两种不同的形式使用相同的数据网格值?

我有一个网格视图,其中显示了巴士列表及其出发地点和目的地以及行程日期时间..

还有一个用户主页,用户在其中预订座位,在用户页面中我必须显示前面提到的数据网格视图的内容

我使用了代码

    public static string SetValueForText1 = "";
    public static string SetValueForText2 = "";
    public static string SetValueForText3 = "";
    public static string SetValueForText4 = "";
    public static string SetValueForText13 = "";

        int i = gv_bus.SelectedCells[0].RowIndex;
        SetValueForText16 = gv_bus.Rows[i].Cells[2].Value.ToString();
        SetValueForText1 = gv_bus.Rows[i].Cells[3].Value.ToString();
        SetValueForText2 = gv_bus.Rows[i].Cells[4].Value.ToString();
        SetValueForText3 = gv_bus.Rows[i].Cells[5].Value.ToString();
        SetValueForText4 = gv_bus.Rows[i].Cells[6].Value.ToString();

在用户主页中我使用了此代码

        lbl_startng1.Text =BUS_BOOKING.BUS_PAGE.SetValueForText1;
        lbl_destination1.Text = BUS_BOOKING.BUS_PAGE.SetValueForText2;
        lbl_trip1.Text = BUS_BOOKING.BUS_PAGE.SetValueForText3;
        lbl_dur1.Text = BUS_BOOKING.BUS_PAGE.SetValueForText4;
        lbl_no1.Text = BUS_BOOKING.BUS_PAGE.SetValueForText13;

但这不起作用,因为我们在调试时加载了用户页面并且它显示了空标签

请大家帮忙。提前致谢

【问题讨论】:

    标签: c# sql winforms datagridview


    【解决方案1】:

    有几种方法可以做到这一点,这个网站上有很多例子。

    Example Here

    我会使用自定义事件并让您的第二个表单订阅您第一个表单上的事件。

    您可以在第二个表单上公开属性并从第一个表单更新。

    我会研究第一个选项,因为它更干净。

    【讨论】:

      【解决方案2】:

      这只是理论,但不能简单的通过第二种形式的构造函数将数据源对象传递给第二种形式吗??

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多