簡體   English   中英

在另一種形式的文本框中顯示datagridview的值

[英]display the value of datagridview in the textboxes present in another form

我們如何以兩種不同形式使用相同的數據網格值?

我有一個網格視圖,其中顯示了公交車的列表及其起始位置和目的地以及行程日期時間。

並且還有一個用戶主頁,用戶在其中預訂座位,並且在用戶頁面中,我必須顯示前面提到的數據網格視圖的內容

我用了代碼

    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;

但這不起作用,因為用戶頁面在我們調試時加載,並且顯示空標簽

任何人請幫忙。 提前致謝

有幾種方法可以做到這一點,並且在此站點上有很多示例。

這里的例子

我會使用自定義事件,並讓您的第二個表單訂閱第一個表單上的事件。

您可以在第二個表單上顯示屬性,然后從第一個表單進行更新。

我會研究第一種方法,因為它更清潔。

這只是理論上的問題,但是您不能簡單地通過第二種形式的構造函數將數據源對象傳遞給第二種形式嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM