Home Forums WinForms controls Xceed Grid for WinForms loosing selected value when changing cells

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

    I am building an unbound grid dynamically and in one of the cells I am using a combobox to edit/view. Everything is working fine until you select the value from the combobox and change cells, the value disappears. Here is my code:

    <code>
    Xceed.Grid.Column colClient = new Xceed.Grid.Column(“CLIENT”, typeof(string));
    Xceed.Grid.Column colProject = new Xceed.Grid.Column(“PROJECT”, typeof(string));
    Xceed.Grid.Column colSampleSet = new Xceed.Grid.Column(“SAMPLE_SET”, typeof(string));
    Xceed.Grid.Column colMatrix = new Xceed.Grid.Column(“MATRIX”, typeof(string));
    Xceed.Grid.Column colNumSamples = new Xceed.Grid.Column(“NUMBER_OF_SAMPLES”, typeof(long));

    gridControl1.Columns.Add(colClient);
    gridControl1.Columns.Add(colProject);
    gridControl1.Columns.Add(colSampleSet);
    gridControl1.Columns.Add(colMatrix);
    gridControl1.Columns.Add(colNumSamples);

    Xceed.Grid.DataRow myRow = gridControl1.DataRows.AddNew();
    myRow.Cells[“CLIENT”].Value = this.ClientName;
    myRow.Cells[“PROJECT”].Value = this.ProjectName;
    myRow.Cells[“SAMPLE_SET”].Value = this.SampleSetName;
    myRow.Cells[“MATRIX”].Value = this.MatrixName;
    myRow.Cells[“NUMBER_OF_SAMPLES”].Value = this.NumberOfSamples;
    myRow.EndEdit();

    Xceed.Grid.Column colParam;

    // loop through selected parameters and create their columns
    arrParameters = this.Parameters;
    for (int i = 0; i < arrParameters.Count; i++)
    {
    strCellName = arrParameters[i].ToString();
    // get data type for parameter
    string strType = GetType(strCellName);
    switch (strType)
    {
    case “STRING”:
    colParam = new Xceed.Grid.Column(strCellName, typeof(string));
    gridControl1.Columns.Add(colParam);
    break;
    case “LONG”:
    colParam = new Xceed.Grid.Column(strCellName, typeof(long));
    gridControl1.Columns.Add(colParam);
    break;
    case “INT”:
    colParam = new Xceed.Grid.Column(strCellName, typeof(int));
    gridControl1.Columns.Add(colParam);
    break;
    case “COLOR”:
    colParam = new Xceed.Grid.Column(strCellName, typeof(Color));
    colorComboEdit = new Xceed.Grid.Editors.GridComboBox();
    colorComboView = new ComboBox();
    colorComboView.DropDownStyle = ComboBoxStyle.DropDownList;
    // create new instance of color
    System.Drawing.Color myColor = new System.Drawing.Color();
    // Get the type of instance
    Type myType = myColor.GetType();
    foreach (PropertyInfo p1 in myType.GetProperties())
    {
    colorComboEdit.Items.Add(p1.Name);
    colorComboView.Items.Add(p1.Name);
    }

    colParam.CellEditor = new CustomEditor(colorComboEdit, “Text”, true);
    colParam.CellViewer = new ControlViewer(colorComboView, “Text”);

    gridControl1.Columns.Add(colParam);
    break;
    }
    }
    </code>

    Does anyone have any ideas what I am missing so that once the value is selected from the combobox and the cell focus has changed why i’m loosing the selected value?

    Thank you

    Imported from legacy forums. Posted by Nathan (had 3226 views)

    User (Old forums)
    Member
    Post count: 23064

    Instead of using 2 ComboBoxes (1 for viewing, 1 for editing), just use for both viewing and editing. If you use a GridComboBox, you don’t have to wrap it in a CustomEditor/ControlViewer. Like this:<pre>Xceed.Grid.Editors.GridComboBox colorCombo = new Xceed.Grid.Editors.GridComboBox();
    Type colorType = typeof(System.Drawing.Color);
    foreach(PropertyInfo p1 in colorType.GetProperties(BindingFlags.Public | BindFlags.Static))
    colorCombo.Items.Add(p1.Name);
    colParam.CellEditor = colorCombo;
    colParam.CellViewer = colorCombo;</pre>

    Imported from legacy forums. Posted by Tommy (had 472 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Tommy,

    Thank you for your reply. I tried using the code you suggested and it produces the same results as what I was doing before. It works, but when I select a value from the colorCombo and then leave the cell, it looses the value that I selected. Here is what my code looks like now:

    <code>
    colParam = new Xceed.Grid.Column(strCellName, typeof(Color));

    colorCombo = new Xceed.Grid.Editors.GridComboBox();

    // create new instance of color
    System.Drawing.Color myColor = new System.Drawing.Color();
    // Get the type of instance
    Type colorType = myColor.GetType();

    foreach (PropertyInfo p1 in colorType.GetProperties(BindingFlags.Public | BindingFlags.Static))
    {
    colorCombo.Items.Add(p1.Name);
    }

    colParam.CellEditor = colorCombo;
    colParam.CellViewer = colorCombo;
    gridControl1.Columns.Add(colParam);

    myRow.Cells[strCellName].LeavingEdit += new Xceed.Grid.LeavingEditEventHandler(myCellValueChanged);

    </code>

    myCellValueChanged method:

    <code>
    private void myCellValueChanged(object sender, Xceed.Grid.LeavingEditEventArgs e)
    {
    Xceed.Grid.Cell cell = sender as Xceed.Grid.Cell;
    Xceed.Grid.CellRow row = cell.ParentRow;
    row.Cells[strCellName].Value = colorCombo.Text;
    }
    </code>

    Am I missing anything else?

    Thank you

    Imported from legacy forums. Posted by Nathan (had 601 views)

    User (Old forums)
    Member
    Post count: 23064

    I got it working now, looks like it had to do with the type on that column.

    <code>
    colParam = new Xceed.Grid.Column(strCellName, typeof(Color));
    </code>

    changed to typeof(string) and now it’s working.

    Thanks for your reply Tommy

    Imported from legacy forums. Posted by Nathan (had 3982 views)

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