2009-11-10 74 views
0

我正在研究C#應用程序,並且需要爲用戶提供一個用戶友好的環境來工作。這個想法是,用戶使用他/她的ID並且密碼,因此只有與用戶相關的數據纔會顯示在表格中。我已經想出瞭如何做到這一點,但現在用戶需要能夠編輯表格的內容,因爲它只是爲用戶提供友好的界面。顯示MySql數據的表格,用戶可以編輯

我應該用什麼樣的表格組件來實現這個目標?我需要能夠加載數據並將編輯後的數據保存回數據庫,但我還需要能夠將顏色分配給單個單元格和邊框,以使其看起來更加用戶友好。另外我更喜歡編輯表格內容的點擊和編輯方式。

我已經嘗試過使用DataGridView,但是在定製它的外觀方面卻不足。

是否有另一個很好的.net組件可以用來實現這個功能?


編輯:這是一個Windows窗體桌面應用程序。

+0

這是一個桌面或Web應用程序?有可用的工具包和組件,但通常特定於環境類型,我不想提出錯誤的建議。 – ChrisF 2009-11-10 13:00:34

+0

...如果你使用桌面,你在用什麼,WPF或WINFORM? – Yogesh 2009-11-10 13:03:01

+0

這是一個桌面應用程序。它也只能在單個桌面上運行。 – Pieter888 2009-11-10 13:03:37

回答

2

使用CellFormatting事件他們自己的代碼綁定到DataGrid

例如當改變單個細胞:

private void dgColorCodeKey_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 
{ 
    if (e.RowIndex >= 0) 
    { 
     //if we are binding a cell in the Color column 
     if (e.ColumnIndex == colColor.Index) 
     { 
      //ColorCode is a custom object that contains the name of a System.Drawing.Color 
     ColorCode bindingObject = (ColorCode)dgColorCodeKey.Rows[e.RowIndex].DataBoundItem; 
     dgColorCodeKey[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.FromName(bindingObject.Color); 

     //set this property to true to tell the datagrid that we've applied our own formatting 
     e.FormattingApplied = true; 
     } 
    } 
} 

此外,請參閱本Data Grid FAQ對於如何在一個非常好的,清晰的描述數據網格的工作原理以及各種方法和事件的作用。

+0

非常感謝 – Pieter888 2009-11-10 15:33:48