WinFom應用程式資料操作技巧

來源:互聯網
上載者:User
1. 在建立資料繫結表單表單時,點擊"資料"菜單,開啟"資料來源"表單,可以對當前DataSet快捷綁定.
2. 向資料集添加驗證: 雙擊DataSet 設計工具的資料列切換到代碼
引用:http://msdn2.microsoft.com/zh-cn/library/ms171930(VS.80).aspx
添加代碼來驗證 e.ProposedValue 包含大於 0 的值。如果建議值小於或等於 0,則設定列來指示其包含錯誤。(雙擊表名(標題列中的“Order Details”)會建立 RowChanging 事件的事件處理常式。)
將下面的代碼粘貼到“Add user code here”(此處添加使用者代碼)注釋下的列變更事件處理常式中:

// C#
// Add the following code
// to the partial class.
    public override void EndInit()
    {
        base.EndInit();
        Order_DetailsRowChanging += TestRowChangeEvent;
    }

    public void TestRowChangeEvent(object sender, Order_DetailsRowChangeEvent e)
    {
        if ((short)e.Row.Quantity <= 0)
        {
            e.Row.SetColumnError("Quantity", "Quantity must be greater than 0");
        }
        else
        {
            e.Row.SetColumnError("Quantity", "");
        }
    }
然後再在介面添加ErrorProvider 控制項擷取錯誤提示: DataSource=要驗證的資料來源, ContainerControl = 表單容器物件;

我雙擊資料列時,並沒有自動建置事件代碼,先學習下,以後再試試是否這樣做有效?
找到答案:“DataSet 設計工具”並不自動為此 C# 事件建立事件處理常式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.