Multiline text in DataGridView Cell

user3007740

I am trying to display text in multiple lines in a DataGridView Cell. I don't want to use the Wrap mode because the text is not very lengthy. I just want to show the first word on the first line and the second one on the next something like this. Note the bold text on second line.


Name: abc
City: xyz

I tried doing it using Environment.NewLine and "\r\n" but neither works.

private void dgv_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        foreach (DataGridViewRow dgvrow in dgv.Rows)
        {  
            if (dgv.CurrentCell.ColumnIndex == dgv.Columns["Name"].Index)
            {
                DataGridViewCell dgvcell = (DataGridViewCell)dgvrow.Cells["Name"];
                string Name = dgvcell.Value.ToString();
                string City = Name.Substring(Name.IndexOf("City:"));
                Name = Name.Substring(0, Name.IndexOf("City:")) + Environment.NewLine + City;
                dgvcell.Value = Name;
            }
        }
    }

Can anyone suggest how this can be achieved? Thanks.

user3007740

I fixed it by handling the DataGridView_CellFormatting event and formatting the text as required. Thanks everyone for your suggestions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiline datagridview cell to display First Line only

From Dev

macro for Multiline text in cell to truncate

From Dev

Merge DataGridView Image cell with text cell

From Dev

Multiline text in a table cell using bootstrap

From Dev

Powershell work with multiline text in Excel cell

From Dev

Copying a multiline text into a single cell in Excel

From Dev

Multiline text in a table cell using bootstrap

From Dev

How to change text of the top left cell of a datagridview?

From Dev

Change text of a cell on dataGridView_CellFormatting

From Dev

Extract Multiline text from Excel cell- macro

From Dev

change datagridview cell type containing text vaue "true" text to checkbox

From Dev

How to get the text from current cell in datagridview textchanged event?

From Dev

.NET Windows forms DataGridView Cell text disappears when added programatically

From Dev

Change color of only part of text inside a DataGridView cell

From Dev

Loading cell values in dataGridView from text file C#

From Dev

how to add text to a dataGridView cell in different form c#

From Dev

Select first row of DataGridView and display cell contents in text boxes

From Dev

Highlight the particular text inside a datagridview cell in c#windows application

From Dev

Center Align Cell Text in Vb.Net DataGridView

From Dev

Custom Textbox Zoom - Return text to active datagridview cell?

From Dev

Retrieve partly selected text when the cell is in edit mode in DataGridView

From Dev

Change textcolor of a row in a datagridview if a cell contains part of text c#

From Dev

Editable multiline cell in TableView

From Dev

How to set some text to datagridview cell when its cell contains 0 value in c#?

From Dev

How to set some text to datagridview cell when its cell contains 0 value in c#?

From Dev

PDFJet-Open-source: How to set multiline text inside Cell object

From Dev

How to display a multiline text in a StringGrid Cell (Delphi XE6 - Android)

From Dev

How to display a multiline text in a StringGrid Cell (Delphi XE6 - Android)

From Dev

Change of the edited cell in a datagridview cell

Related Related

  1. 1

    Multiline datagridview cell to display First Line only

  2. 2

    macro for Multiline text in cell to truncate

  3. 3

    Merge DataGridView Image cell with text cell

  4. 4

    Multiline text in a table cell using bootstrap

  5. 5

    Powershell work with multiline text in Excel cell

  6. 6

    Copying a multiline text into a single cell in Excel

  7. 7

    Multiline text in a table cell using bootstrap

  8. 8

    How to change text of the top left cell of a datagridview?

  9. 9

    Change text of a cell on dataGridView_CellFormatting

  10. 10

    Extract Multiline text from Excel cell- macro

  11. 11

    change datagridview cell type containing text vaue "true" text to checkbox

  12. 12

    How to get the text from current cell in datagridview textchanged event?

  13. 13

    .NET Windows forms DataGridView Cell text disappears when added programatically

  14. 14

    Change color of only part of text inside a DataGridView cell

  15. 15

    Loading cell values in dataGridView from text file C#

  16. 16

    how to add text to a dataGridView cell in different form c#

  17. 17

    Select first row of DataGridView and display cell contents in text boxes

  18. 18

    Highlight the particular text inside a datagridview cell in c#windows application

  19. 19

    Center Align Cell Text in Vb.Net DataGridView

  20. 20

    Custom Textbox Zoom - Return text to active datagridview cell?

  21. 21

    Retrieve partly selected text when the cell is in edit mode in DataGridView

  22. 22

    Change textcolor of a row in a datagridview if a cell contains part of text c#

  23. 23

    Editable multiline cell in TableView

  24. 24

    How to set some text to datagridview cell when its cell contains 0 value in c#?

  25. 25

    How to set some text to datagridview cell when its cell contains 0 value in c#?

  26. 26

    PDFJet-Open-source: How to set multiline text inside Cell object

  27. 27

    How to display a multiline text in a StringGrid Cell (Delphi XE6 - Android)

  28. 28

    How to display a multiline text in a StringGrid Cell (Delphi XE6 - Android)

  29. 29

    Change of the edited cell in a datagridview cell

HotTag

Archive