Home Forums WinForms controls Xceed Grid for WinForms Allow edit on only one cell in grid

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15246 |

    Hi have a grid on my form and I want the user to be able to only edit one cell, all the rest are to be readonly. I have the following code:

    DataView dv = new Order(MainForm.ConnectionString).GetAllOrderItems(_orderID).Tables[0].DefaultView;

    dgvOrderItems2.Columns.Clear();
    dgvOrderItems2.AutoCreateColumns = false;
    DataBoundColumn col0 = new DataBoundColumn(“ProductName”);
    col0.Title = “Product”;
    col0.ReadOnly = true;
    dgvOrderItems2.Columns.Add(col0);

    DataBoundColumn col1 = new DataBoundColumn(“UnitPrice”);
    col1.Title = “Unit Price”;
    col1.ReadOnly = true;
    dgvOrderItems2.Columns.Add(col1);

    DataBoundColumn col2 = new DataBoundColumn(“Quantity”);
    col2.Title = “Quantity”;
    col2.ReadOnly = true;
    dgvOrderItems2.Columns.Add(col2);

    DataBoundColumn col3 = new DataBoundColumn(“BatchNumber”);
    col3.Title = “Batch Number”;

    col3.ReadOnly = false;
    col3.CellEditorManager = new TextEditor();
    dgvOrderItems2.Columns.Add(col3);

    DataBoundColumn col4 = new DataBoundColumn(“TotalPrice”);
    col4.Title = “Total Price”;
    col4.ReadOnly = true;
    dgvOrderItems2.Columns.Add(col4);

    DataBoundColumn col5 = new DataBoundColumn(“Unit”);
    col5.Title = “Unit”;
    col5.ReadOnly = true;
    dgvOrderItems2.Columns.Add(col5);

    dgvOrderItems2.DataSource = dv;

    this displays the columns fine. I’m having trouble getting the BatchNumber column to show the editor when it is double clicked?

    Any ideas would be great… thank

    Imported from legacy forums. Posted by ric (had 3829 views)

    User (Old forums)
    Member
    Post count: 23064

    Your code looks fine, but there could be an exception (e.g. data conversion from the cell to the editor) that is swallowed by the grid, and you don’t see because your debugger is not set to break on all exceptions (Debug Menu -> Exceptions -> Common Language Runtime Exception, then select “Break into the debugger” radio button in VS2003, or select “Thrown” CheckBox in VS2005).

    If you are in VS2005, make sure the “Enable Just My Code” CheckBox is unselected (Tools Menu -> Options -> Debugging -> General).

    This will make sure that no exceptions are swallowed by the grid, and that the debugger will break in any part of the code, not just yours.

    Imported from legacy forums. Posted by André (had 233 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi thanks for the reply.

    Did what you said and I don’t get any exceptions. Is there any chance you could send or post a simple example of a grid with the above columns and the ability to only edit one cell?

    Thanks

    Imported from legacy forums. Posted by ric (had 367 views)

    User (Old forums)
    Member
    Post count: 23064

    I made a change to the Data row Template and set AllowCellNavigation = true and I can not select the cell.

    I have the following action:

    private void dataRowTemplate1_EditEnded(object sender, EventArgs e)
    {
    Xceed.Grid.Cell cell = (Xceed.Grid.Cell)sender;
    int itemID = int.Parse(cell.Value.ToString());
    MessageBox.Show(“itemID:” + itemID);
    }

    What I’m trying to do is show a message that shows the value of the text that has just been updated after the user has finished the update. But the above does not seem to work. Am I doing this right?

    Imported from legacy forums. Posted by ric (had 366 views)

    User (Old forums)
    Member
    Post count: 23064

    basically all I want to do it capture what info has been entered in the update and show this to the user when they have finished the update or when the grid looses focus

    Imported from legacy forums. Posted by ric (had 232 views)

    User (Old forums)
    Member
    Post count: 23064

    First, it would be better to use the EditLeft event on the Cell instead of the EditEnded on the Row.

    e.g.:

    dataRowTemplate1.Cells[ “BatchNumber” ].EditLeft += …

    In the event handler, you should be able to cast the sender to a Cell, and get the new value.

    If this does not solve your issue, maybe it would be simpler if you would <a href=”mailto:support@xceedsoft.com”>send</a> a sample application reproducing what you are doing (you can use the Northwind DB installed along Xceed components as a substitute to your own data source), so we can investigate the issue further.

    You will find the Northwind DB here on XP :

    C:\Documents and Settings\All Users\Application Data\Xceed Software\Sample Data

    And here on Vista :

    C:\ProgramData\Xceed Software\Sample Data

    Imported from legacy forums. Posted by André (had 5114 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.