Renaming a column makes column information disapear.

I have a table that has a feature where you can rename a column by using a text change event handler. So as a user is typing into a text box, the name of the column is being updated at the same time.


I have an issue where I type in information into a few cells, then I decide to rename the column. As soon as I type in the first letter, all the cells that have information in that column, disappear.

To me it looks like some binding issue, where the column mapping isn't translating properly between the GridGroupingControl Table and the Data Table.


This is where I've just added a column and then edited some cells.

Image_4489_1706738636367


This is when I go to rename the column, all the information disappears.

Image_4675_1706738719970


Below is how I've been updated the column names in the grid and the data table.


if (mTranslationsGrid.DataTable.Columns[originalHeaderText].ColumnName != updatedName)
{
mTranslationsGrid.DataTable.Columns[originalHeaderText].ColumnName = updatedName;
}


mTranslationsGrid.Grid.TableDescriptor.VisibleColumns[originalHeaderText].Name = updatedName;
mTranslationsGrid.Grid.TableDescriptor.Columns[originalHeaderText].MappingName = updatedName;
mTranslationsGrid.Grid.TableDescriptor.Columns[originalHeaderText].HeaderText = updatedName;
mTranslationsGrid.Grid.TableDescriptor.Columns[originalHeaderText].Name = updatedName;


5 Replies

SB Sweatha Bharathi Syncfusion Team February 1, 2024 12:41 PM UTC

Hi Adrian Negrillo,


We have analyzed your query and the code snippet you provided. It seems that you are attempting to change the column name based on what the user is typing into a text box. In the code you provided, you changed the HeaderText and Name properties value, but you also changed the MappingName property value. However, in the datatable, the mapping name is already assigned and has a corresponding value. The data in the GridGroupingControl is maintained based on the MappingName.


If you try to change the MappingName property, the table will not have that kind of MappingName and the changed MappingName will not have any data. As a result, the information in the column will disappear.


Kindly change the HeaderText and Name of the column as it will not have any impact on the data. we have provided sample for your reference , kindly refer the sample and let us know if you have any further concerns on this.


Code Snippet:


private void TextBox1_TextChanged(object sender, System.EventArgs e)

 {

     UpdatedName=  this.textBox1.Text;

     gridGroupingControl1.TableDescriptor.VisibleColumns[0].Name = UpdatedName;

     gridGroupingControl1.TableDescriptor.Columns[0].HeaderText = UpdatedName;

     gridGroupingControl1.TableDescriptor.Columns[0].Name = UpdatedName;

 

 }



Image Reference:




Attachment: GridGroupingControl_Demo4_8_3f0f2b02.zip


AN Adrian Negrillo replied to Sweatha Bharathi February 29, 2024 11:39 PM UTC

Hey thanks for the reply however I'm faced with another issue, where if I update a cell in that column and then I add a new column. The information in the first set disappear.


Reproduction steps.

Create New Column > Rename Column and Modify Row Cell

Original Column Name: New Translation: 0

New Column Name: New Column

Image_9778_1709249415363


Add New Column > The modified cell data disappears.

Image_4099_1709249477485


My code for adding a column is below.


if (!_mGrid.TableDescriptor.Columns.Contains(columnName))
{

    if (!_mGrid.TableDescriptor.Columns.Contains(columnName))
    {
        _mGrid.TableDescriptor.Columns.Add(columnName);
        _mGrid.TableDescriptor.VisibleColumns.Add(columnName);


_mGrid.TableDescriptor.Columns[columnName].Appearance.ColumnHeaderCell.Borders.Bottom=newGridBorder(GridBorderStyle.Solid, Color.FromArgb(176, 176, 176), GridBorderWeight.Thin);
        _mGrid.TableDescriptor.Columns[columnName].Appearance.ColumnHeaderCell.BackColor=SystemColors.ControlLight;
    }
}



if (!_mDataTable.Columns.Contains(columnName))
{
    DataColumnnewColumn=newDataColumn(columnName);
    newColumn.Caption=columnName;



    _mDataTable.Columns.Add(newColumn);
}


I've tried refreshing the control to see if that's worked but didn't do anything, so I'm not sure if I need to do something extra to hold the modified information.



SB Sweatha Bharathi Syncfusion Team March 1, 2024 02:56 PM UTC

Hi Adrian Negrillo ,



We have analyzed your query and prepared a sample based on the provided code snippet.


  1. We are modifying the cell in the existing column and adding a new column.


  1. First, create a new column, rename it, modify the cell in existing column, and add a value in the new column. In both cases mentioned above, the reported scenario is not replicating. It is working fine as expected. We have provided a sample for your reference.


Kindly review the sample. If you still encounter the issue, please modify the sample based on your scenario. This will help us proceed further.



Attachment: GridGroupingControl_Demo4_8_de4e024b.zip


AN Adrian Negrillo May 17, 2024 02:02 AM UTC

Hey Sweatha, 


Sorry for the late reply this has been resolved. 

Thanks!



JS Jayashree Suresh Anand Syncfusion Team May 20, 2024 09:16 AM UTC

Hi Adrian Negrillo,

Glad that your issue is resolved! Please let us know if you need further assistance, we will be happy to help. 

Regards,

Jayashree 


Loader.
Up arrow icon