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

Need Support on WinForms in Telerik

5 Answers 125 Views
Telerik Trainer
This is a migrated thread and some comments may be shown as answers.
A
Top achievements
Rank 1
A asked on 25 Sep 2010, 02:01 AM
Hi Friends,
       Just Before two days we Purchased Telerik's Premium Collection Tool for .NET. I am finding it difficult to do the following operations

  • To Add  Row Header in RadGridView
  • To Change the BackColor of specfied cells in RadGridView
  • To Center align the cell contents in RadGridView

Can anyone guide me regarding these problems...


Regards,

Balaji. A

TriAcme Technologies

5 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 30 Sep 2010, 08:57 AM
Hi A,

You can change the back color and content alignment of the cell in the CellFormatting event:

private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    bool condition = true;
 
    if (condition)
    {
        e.CellElement.BackColor = Color.Red;
        e.CellElement.GradientStyle = GradientStyles.Solid;
        e.CellElement.DrawFill = true;
        e.CellElement.TextAlignment = ContentAlignment.MiddleRight;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.TextAlignmentProperty, ValueResetFlags.Local);
    }
}

In RadGridView each view can have only one header row. That means that only in hierarchy mode you will have more than one header rows. Can you illustrate what you want to achieve? What is your scenario?

I am looking forward to your response.

Best wishes,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Allwin
Top achievements
Rank 1
answered on 30 Sep 2010, 03:15 PM
Hi Svett,
         
             Thanks for considering my post. Your solution to change the BackColor of the radgridview helps me solving my problem in addition what I desire is when i click a particular cell its backcolor has to be changed and it should be retained.

              Coming to Row Header Values in RadGridView, What my gridview is going to hold is daily wages of employees. I am able to set Date as a Row Header Value Dynamically (eg: RadGridView1.Columns(1).HeaderText = "01 Oct, 10") but I could not set the Employee names from Database(Access) as my Row header values in radgrid

             And one more thing Can I perform Drag and Drop operation for cells within RadGridView if possible pls send me some samples regarding this ....

             Thank You..

Regards,

Balaji. A
(balaji_07@live.com)


TriAcme Technologies
(triacmeapex@gmail.com)

0
Nikolay
Telerik team
answered on 01 Oct 2010, 12:10 PM
Hi Balaji,

Thank you for getting back to us.

In order to change the color of a cell when it is clicked, you can subscribe to the CellClick event of RadGridView and modify the Style object of the clicked cell in the CellClick handler:
public Form1()
{
    InitializeComponent();
  
    this.radGridView1.CellClick += new Telerik.WinControls.UI.GridViewCellEventHandler(radGridView1_CellClick);
}
  
void radGridView1_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    e.Row.Cells[e.Column.FieldName].Style.CustomizeFill = true;
    e.Row.Cells[e.Column.FieldName].Style.DrawFill = true;
    e.Row.Cells[e.Column.FieldName].Style.BackColor = Color.Red;
    e.Row.Cells[e.Column.FieldName].Style.CustomizeBorder = true;
    e.Row.Cells[e.Column.FieldName].Style.DrawBorder = true;
    e.Row.Cells[e.Column.FieldName].Style.BorderGradientStyle = Telerik.WinControls.GradientStyles.Solid;
    e.Row.Cells[e.Column.FieldName].Style.BorderColor = Color.Red;
}

For additional information about the Style object, please refer to our Examples application, section GridView >> Customize >> Style Cells.

In your second enquiry, you are talking about Row Header, but you are actually setting the text of the column header. In case you want to set the value of the column header, however, I am not sure that I understand the exact scenario. Please send me a sample project in the support ticket that you have opened for the same topic and provide me with additional details about the place where you want to set the Employees' names.

As to your question concerning the drag and drop functionality, the desired behavior is easily achievable thanks to RadDragDropService. For additional information, please refer to the attached sample project.

I hope this helps.

Sincerely yours,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Allwin
Top achievements
Rank 1
answered on 04 Oct 2010, 04:08 PM
Hi Friends,
 
                  Once Again back to you regarding the same query. I have attached the screen shot of what i have done using ordinary datagridview in .NET. My problem with radgridview is i can't set those backcolors while loading data in the grid and also i cant add row header values (4001, 4002,4003 etc). Hope you can understand my prblm. Pls reply asap..


______

Balaji. A

www.triacme.com
0
Nikolay
Telerik team
answered on 04 Oct 2010, 04:52 PM
Hi Allwin,

The RadGridView feature regarding the cells' colors that you need is Conditional Formatting. It sets a custom color to a cell depending on the value of that cell. You can read more about this functionality in this help article.

As to the row headers, you should handle the ViewCellFormatting event in order to modify the non-data cells of RadGridView. Please consider the code snippet below:
public Form1()
{
    InitializeComponent();
  
    this.radGridView1.ViewCellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(radGridView1_ViewCellFormatting);
}
  
void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement is GridRowHeaderCellElement)
    {
        if (e.CellElement.RowInfo.Cells["EmployeeID"].Value != DBNull.Value
            && e.CellElement.RowInfo.Cells["EmployeeID"].Value != null)
        {
            e.CellElement.Text = e.CellElement.RowInfo.Cells["EmployeeID"].Value.ToString();
        }
    }
}

As you can see, I am setting the values of the row header cells depending of the values of the EmployeeID cells which belong to the respective data rows. Feel free to modify this snippet according to your specific needs.

Additionally, you can set the width of the row header column using the RowHeaderColumnWidth property:
this.radGridView1.GridViewElement.TableElement.RowHeaderColumnWidth = 100;

I hope this helps.

Sincerely yours,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Telerik Trainer
Asked by
A
Top achievements
Rank 1
Answers by
Svett
Telerik team
Allwin
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or