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

FormatString

5 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Somnath
Top achievements
Rank 1
Somnath asked on 21 Feb 2011, 12:22 PM
HI

I have a Radgridview Which has a ComboBoxColumn---'Account'

The data from database came in this Fashion--  (XXXXXX) XXXXXXXXXXXXX
for e.g -----  (Expence) Computer and Internet Expence
                    (Income) Investment Income

I want to show the data as---

Text within Brackets Should display in Blue color
text outside of Brackets should display in Black color

Suggest me any way to Show this....
Thanks

5 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 21 Feb 2011, 01:01 PM
Hello Somnath,

You can achieve this using the CellFormatting event and turning off DisableHtmlRendering on the column.

For exmaple:
myColumn.DisableHTMLRendering = false;

this.radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_CellFormatting);

private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo.Name == "MyColumn" && e.CellElement.Value != null)
    {
        e.CellElement.Text = e.CellElement.Value.ToString();
        string s = e.CellElement.Text;
        s = s.Replace("(", "(<color=Blue>");
        s = s.Replace(")", "<color=Black>)");
        s = "<html><color=Black>" + s + "</html>";
        e.CellElement.Text = s;
    }
}


You could also skip the CellFormatting by chosing to include the required HTML in your string from your datasource.
For more information on HTML-Like Formatting, see this link

Hope that helps
Richard
0
Somnath
Top achievements
Rank 1
answered on 21 Feb 2011, 01:24 PM
HI
Actually,

 I Want  when user click on the ComboBoxColumn then Items Should Display in
(XXXXX ) XXXXXXXX    format
Thanks
0
Richard Slade
Top achievements
Rank 2
answered on 21 Feb 2011, 02:14 PM
Hello Somnath,

The very easiest way, is to change the text part of your data source. It will then show in that format that you require

e.g

"<html>(<color=Blue>Income<color=Black>) Investment Income</html>"


Hope that helps
Richard

0
Somnath
Top achievements
Rank 1
answered on 21 Feb 2011, 04:01 PM

Hello Richard

The Comboboxcolumn  having 41 different Accounts....
20 belongs to 'Expence' Account Type
15 belongs to 'Income' Account Type
remaiing 6 from 'Other' Account Type

So Please Can you Provide Proper Code on this issue......

Thaks a Lot.........
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 21 Feb 2011, 04:25 PM

Somnath,

You need to handle the CellEditorInitialized event and then change the item text as per my previous post.

For exmaple:

this.radGridView1.CellEditorInitialized += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellEditorInitialized);

private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadDropDownListEditor listEditor = this.radGridView1.ActiveEditor as RadDropDownListEditor;
    if (listEditor == null)
    {
        return;
    }
    RadDropDownListEditorElement editorElement = listEditor.EditorElement as RadDropDownListEditorElement;
    foreach (RadListDataItem item in editorElement.Items)
    
        string s = item.Text; 
        s = s.Replace("(", "(<color=Blue>"); 
        s = s.Replace(")", "<color=Black>)"); 
        s = "<html><color=Black>" + s + "</html>";
        item.Text = s;
    }
}

I hope you find that helpful
Richard
Tags
GridView
Asked by
Somnath
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Somnath
Top achievements
Rank 1
Share this question
or