2015.1.10 解決DataGridView SelectionChanged事件自動觸發問題


DataGridView SelectionChanged事件總是在數據源更改時自動觸發,這點很討厭。

可用CellClick和KeyUp事件和一個函數替代SelectionChanged事件

private void dvpt_CellClick(object sender, DataGridViewCellEventArgs e)

{

     if (e.RowIndex < 0) return;//如果不是單擊列表頭

     MySelectionChanged();

}

private void dvpt_KeyUp(object sender, KeyEventArgs e)

{

    if (e.KeyData == Keys.Down || e.KeyData == Keys.Up)

    {

      MySelectionChanged();

    }

}

public void MySelectionChanged()

{

     if (dvpt.SelectedRows.Count == 0) return;

....................................................................................

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM