This is a migrated thread and some comments may be shown as answers.

multi line textbox in row

8 Answers 218 Views
GridView
This is a migrated thread and some comments may be shown as answers.
andi
Top achievements
Rank 1
andi asked on 27 Jan 2008, 12:07 PM
hi,

is there a possibility to display multi line text (text with linebreaks) in a radgridview row?

thanks, andreas

8 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 28 Jan 2008, 02:44 PM
Hi Andreas,

Thank you for writing us.

Currently RadGridView does not support line breaks and word wrapping for its cells content. This is a high priority feature and we are in process of implementing it for one of our upcoming releases. In the meantime you can use the following workaround.
You can insert  Label controls in the cells where you want to have text with line breaks.
The code snippet below demonstrates this technique:

this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting); 
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement.ColumnInfo is GridViewTextBoxColumn && 
        ((GridViewTextBoxColumn)e.CellElement.ColumnInfo).DataField == "Name"
    { 
        if (e.CellElement.Children.Count == 0) 
        { 
            Label label = new Label(); 
            label.Text = e.CellElement.Value.ToString(); 
            label.ForeColor = Color.Black; 
            RadHostItem item = new RadHostItem(label); 
            e.CellElement.Children.Add(item); 
            e.CellElement.ForeColor = Color.Transparent; 
        } 
        else 
        { 
            Label label = (Label)((RadHostItem)e.CellElement.Children[0]).HostedControl; 
            label.ForeColor = Color.Black; 
            label.Text = e.CellElement.Value.ToString(); 
        } 
    } 
 

In case you have further questions, don't hesitate to contact us.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
andi
Top achievements
Rank 1
answered on 29 Jan 2008, 10:56 AM
hi jack,

thanks for xour answer! could you post the code as visual basic code please?

thank you! andreas
0
Jack
Telerik team
answered on 29 Jan 2008, 01:08 PM
Hi Andreas,

Here is the same code in VB (you can use the free code converter that Telerik provides here):

Private Sub radGridView1_CellFormatting(ByVal sender As ObjectByVal e As CellFormattingEventArgs) 
    If TypeOf e.CellElement.ColumnInfo Is GridViewTextBoxColumn AndAlso DirectCast(e.CellElement.ColumnInfo, GridViewTextBoxColumn).DataField = "Name" Then 
        If e.CellElement.Children.Count = 0 Then 
            Dim label As New Label() 
            label.Text = e.CellElement.Value.ToString() 
            label.ForeColor = Color.Black 
            Dim item As New RadHostItem(label) 
            e.CellElement.Children.Add(item) 
            e.CellElement.ForeColor = Color.Transparent 
        Else 
            Dim label As Label = DirectCast(DirectCast(e.CellElement.Children(0), RadHostItem).HostedControl, Label) 
            label.ForeColor = Color.Black 
            label.Text = e.CellElement.Value.ToString() 
        End If 
    End If 
End Sub 

Do not hesitate to write us if you need further assistance.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
andi
Top achievements
Rank 1
answered on 29 Jan 2008, 01:24 PM
thank you very mutch!

i still have two problems:

1. Type 'RadHostItem' is not denfined

2. how do i call the sub that you posted in my code?

thanks again,

andreas
0
Jack
Telerik team
answered on 29 Jan 2008, 02:58 PM
Hi Andy,

Here is the answer to your questions:

  1. Add the following code on top of your class definition in order to import the Telerik.WinControls namespace:

    Imports Telerik.WinControls 
  2. The following code construction shows how to attach the RadGridView1_CellFormatting function to the CellFormatting event of the RadGridView:

    AddHandler Me.RadGridView1.CellFormatting, AddressOf RadGridView1_CellFormatting 

Let us know if you need further assistance.

Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
andi
Top achievements
Rank 1
answered on 29 Jan 2008, 03:09 PM
ok, i added the code but nothing happens. don't i  have to do anything else?

andreas
0
andi
Top achievements
Rank 1
answered on 29 Jan 2008, 03:18 PM
i'm sorry, the post before was wrong. there happened something ;)

but now i have the problem that the height of the row is to small. how can i change this?

thanks, andras
0
Jack
Telerik team
answered on 30 Jan 2008, 08:47 AM
Hello Andreas,

We have answered your question in this forum post.

Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
andi
Top achievements
Rank 1
Answers by
Jack
Telerik team
andi
Top achievements
Rank 1
Share this question
or