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

[Solved] Wrapping and Autogenerated Numbering.

3 Answers 187 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Naren
Top achievements
Rank 1
Naren asked on 24 Nov 2010, 01:44 PM
Hi,

1.  I have a grid where i have set  MaxWidth="600" and TextWrapping="Wrap".....it  does wrap the text but when i edit that grid it again shows the content of edited row in single row(line).......
How can i avoid this......
means on editing also it should show the text as it appears on wrapping.....

Please look into attached image for clarification.


 2 .   I have a RadGriView where i have given source to the grid ....
Now i want to add another column to this grid which will show the row number..
How can i achieve this ....a column Serial Number........

3 Answers, 1 is accepted

Sort by
0
Naren
Top achievements
Rank 1
answered on 26 Nov 2010, 05:24 AM
Hi
I got partial solution ..
For my 1st question i added following CellEditTemplate  :
 
<telerik:GridViewDataColumn DataMemberBinding="{Binding Descriptor, Mode=TwoWay}" Header="Description"  IsReadOnly="False"  UniqueName="AttributeDescriptor" MaxWidth="600" TextWrapping="Wrap">
     <telerik:GridViewDataColumn.CellEditTemplate>
              <DataTemplate>
                     <TextBox x:Name="abc" Text="{Binding Descriptor,Mode=TwoWay}" TextWrapping="Wrap"/>
               </DataTemplate>
     </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
Problem with this is before adding CellEditTemplate I was doing validation(if cell contains empty string then showing error message "Please enter description") on event CellValidating(object sender, Telerik.Windows.Controls.GridViewCellValidatingEventArgs e)
as in following code snippet and it was working fine before adding CellValidating
string newValue = Convert.ToString(e.NewValue);
 
 if (newValue != null)
                    {
                        if (newValue != string.Empty)
                        {
                            e.IsValid = true;
                        }
                        else
                        {
                            e.IsValid = false;
                            e.ErrorMessage = "Please enter attribute description";
                        }
                    }
                    else
                    {
                        e.IsValid = false;
                        e.ErrorMessage = "Please enter attribute description";
                    }

But now when i go for edit
string newValue = Convert.ToString(e.NewValue);
newValue return empty string even though grid cell has some previous description and my validation fails....


I got solution for 2nd question..
0
Accepted
Veselin Vasilev
Telerik team
answered on 29 Nov 2010, 09:32 AM
Hi Naren,

We have an online demo for your second question called Row Number. Please check it our here.

As for the first one - you can use our new PreparingCellForEdit event to get a reference to the editing element, a textbox in your case, and set its TextWrapping property to Wrap. Here is a sample:

private void clubsGrid_PreparingCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
    if ((string)e.Column.Header == "Name")
    {
        var tb = e.EditingElement as TextBox;
        tb.TextWrapping = TextWrapping.Wrap;   
    }          
}

This way the validation logic of RadGridView should be intact.

Best wishes,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Naren
Top achievements
Rank 1
answered on 29 Nov 2010, 12:03 PM
Hi Veselin Vasilev,
Thank you. it was helpful.
Tags
GridView
Asked by
Naren
Top achievements
Rank 1
Answers by
Naren
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or