0
votes

I have a DataGridView I'm trying to edit manually.

-grid.ReadOnly is false
-all Columns ReadOnly are false
-EditMode is OnKeyStroke
-not bound to anything
-no data validation

If I enter a value in the grid and then press enter or click onto another cell, the entered value disappears.

I have the following events setup on the DataGridView:
CellMouseDoubleClick

private void trackEditor_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            DataGridView grid = sender as DataGridView;
            //checks if the cell's value contains a 0. If so, change the value to write to 1. If not, assume the cell value is already 0 and keep the value to write to 0
            int val;
            if (grid.CurrentCell.Value == null || int.Parse(grid.CurrentCell.Value.ToString()) == 0)
                val = 1;
            else 
                val = 0;
            grid.CurrentCell.Value = val;
        }

CellValueChanged

private void trackEditor_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string _out = "";
            for (int x = 0; x < trackEditor.ColumnCount; x++) {
                if (trackEditor.CurrentRow.Cells[x].Value != null)
                    _out += x + ":" + trackEditor.CurrentRow.Cells[x].Value + ",";
            }
            richRawTrackData.Text = _out;
        }
1
What is it bound to? Are you using validation? Any other events subscribed to? Please edit into your post any code you think relevantCharlieface
Updated post @CharliefaceCocoaMix86
Is this for every column or only certain ones? column.ValueType and FormattedValueType are what? Any other odd settings?Charlieface
Every column and cell appears to be affected. ValueType is string. I don't have FormattedValueType setCocoaMix86
You don't see the edited value in richRawTrackData.Text ?Chetan

1 Answers

0
votes

I found the answer. By creating a duplicate DGV and comparing Properties one by one, I found that it was the VirtualMode property that prevented entering data. Setting it to false allowed data to be entered now.