![](/img/trans.png)
[英]Set DataGridView Row Background Image in C# Winform Application
[英]Set Location of ListView below DataGridView Active Row in C# Winform
工具:Visual Studio 2010 Ultimate,語言C#,數據庫MySql
你好
我搜索了一陣子,但到目前為止找不到任何合適的解決方案。
我有一個綁定DataGridView的表單,其中包含5列,即ProductID,ProductName,Qty,Price和Amount。 普通數據輸入后,用戶可以單擊按鈕將數據保存到Mysql數據庫,那里沒有問題。
目前,用戶手動輸入ProductID,然后執行Sql命令以獲取ProductName並將其設置為DataGridView ProductName列。 我需要一種在獲得焦點時在ProductID列下方顯示ListView的方法,以便用戶可以從ListView中選擇產品(ProductID和ProductName)並將其設置為用戶當前正在使用的DataGridView的Row。
當用戶單擊或獲得焦點時,是否可以在ProductID單元格下面顯示列表視圖?
謝謝
艾哈邁德
試試下面的代碼,我認為這是一個不錯的開始-但絕對需要改進。 但是請不要像我在上面的評論中提到的那樣,應該處理特殊情況,例如滾動甚至擴展網格,以便ListView
不會隱藏DataGridView
行。
在您的DataGridView
訂閱MouseMove
事件並存儲鼠標位置:
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
mouseLoc = e.Location;
}
您可以將mouseLoc
設置為屬性。
private Point mouseLoc = new Point();
並使用以下代碼訂閱CellMouseDown
事件:
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
listView1.Location = new Point(mouseLoc.X, mouseLoc.Y + dataGridView1[e.ColumnIndex, e.RowIndex].Size.Height);
listView1.BringToFront();
listView1.Refresh();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.