问题
I am trying to find solution for DataGrid in .NET Compact Framework, for cell editing.
Is it even possible to edit cell in default DataGrid in .NET Compact Framework in Windows Mobile, and how to do this?
If it is not possible, what is another solution, maybe some other control if there is free.
回答1:
No, you can't. From the source:
In the .NET Compact Framework, you cannot directly edit the contents of the DataGrid at run time. You must bind controls, such as a TextBox, to your data source and use the DataGrid to display and select records.
You don't have a lot of screen space on a compact device so cell editing would actually be weird. One good way to handle this is to have an editor form that represents entities in the rows. You select a row and then use a button or context menu to initiate an edit. You open the selected row/object in this form. When done editing and clicking OK you commit the changed values to the object that the row represents...
Here is a good article detailing the edit form process I described above. From the linked article:
This example demonstrates techniques for using the DataGrid control with forms for viewing and editing a record that is selected in the DataGrid control, and adding a new record to the database. Note that a user interface must be provided to edit DataGrid values, because editing the DataGrid cells is not supported in the .NET Compact Framework. This example uses the Northwind database, which is installed with Visual Studio.
回答2:
In the book "Programming the compact framework 3.5" by Paul Yao is a nice in-place editing solution for the datagrid in chapter 4.4.9 and following:
excerpt:
"... 4.4.9 Providing In-Place Editing Capability A .NET Compact Framework DataGrid control is used for display only. Unlike its desktop counterpart, it does not provide any data modification capability to the user. To overcome the display-only limitation of the DataGrid control, you must provide the data modification capability yourself. Your application must take two steps to provide in-place editing for a DataGrid control. 1. Present a control capable of accepting input, such as a TextBox, preferably with the text already highlighted,wheneverthe user indicates that he wishes to modify the contents of the CurrentCell. 2. Provide a mechanism for the user to indicate that he has completed, or is canceling the update. If an update was requested,movethe contents of the input control into the CurrentCell. If appropriate, hide the input control....."
The code is available at http://www.paulyao.com/res/code/login.aspx?ReturnUrl=%2fres%2fcode%2fdefault.aspx after registration. Paul Yao provides an example with manual and automatic in-place editing for the DataGrid using a Textbox shown above the datagrid.
来源:https://stackoverflow.com/questions/16042402/strategies-for-cell-editing-inside-datagrid