TrueDBGrid: Line Breaks after copying Data from Excel

Posted by: CEymer on 14 April 2025, 5:46 am EST

  • Posted 14 April 2025, 5:46 am EST

    Hi All,

    We use the TrueDBGrid in our applications for almost 25 years now. For a few months now we are observing a change in behaviour of the grid, that causes us very big headaches…

    Our users copy data from Excel into our applications from time to time. Excel has got the bad habit of ending every value with a line break, even when copying values from one single cell. I’m very sure, that in the past the TrueDBGrid removed these line breaks when inserting data from excel.

    Now we discover more and more strings in our database with line breaks. Exports to csv files suddenly contain these line breaks.

    Could you please have a look into this? How can we get back the old behaviour of the Grid? This is very serious for us.

    Thank you very much for help,

    Christian

  • Posted 15 April 2025, 2:23 am EST

    Hello Christian,

    You can handle KeyDown event of the TrueDBGrid to replace the “/r/n” string in the clipboard text as follows:

    private void C1TrueDBGrid1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control && e.KeyCode == Keys.V)
        {
            var text = Clipboard.GetText().Replace("\r\n", "\t");
            if (c1TrueDBGrid1.EditActive && c1TrueDBGrid1.Editor is TextBox textBoxEditor)
                textBoxEditor.Text = text;
            else
                c1TrueDBGrid1[c1TrueDBGrid1.Row, c1TrueDBGrid1.Col] = text;
            e.Handled = true;
            e.SuppressKeyPress = true;
        }
    }

    Please refer to the attached sample for implementation. (see TrueDBGrid_CopyDataFromExcel.zip)

    Please let us know if it helps and the previous version of TrueDBGrid you were using (that you are comparing the behavior with).

    Regards,

    Uttkarsh.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels