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

button element images not showing in my gridview

4 Answers 134 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patrick Baggett
Top achievements
Rank 2
Patrick Baggett asked on 27 Jul 2012, 08:01 PM

Upgraded to Version 2012.2.726.40 today and have been struggling to get my project working again. 

One thing I noticed right away is that my command buttonelements in my grid no longer display their images.

here's how I am adding them in code:

private void radGridViewJobs_CellFormatting(object sender, CellFormattingEventArgs e)
{
    try
    {
        foreach (RadElement ele in e.CellElement.Children)
        {
            if (ele is RadProgressBarElement)
            {
                e.CellElement.Children.Remove(ele);
                break;
            }
 
        }
 
        if (e.CellElement is GridCommandCellElement && !(e.CellElement.RowElement is GridTableHeaderRowElement))
        {
 
            GridViewCommandColumn column = (GridViewCommandColumn)e.CellElement.ColumnInfo;
            String colname = column.FieldName.ToLower();
            if (colname == "stationview")
            {
                RadButtonElement element = (RadButtonElement)e.CellElement.Children[0];
                element.Image = global::PayerConnectClient.Properties.Resources.workstation;
                element.DisplayStyle = DisplayStyle.Image;
                element.ImageAlignment = ContentAlignment.MiddleCenter;
                 
 
                String myStation = e.CellElement.RowInfo.Cells["workstation"].Value.ToString().Trim();
 
                if (myStation.Length > 0)
                {
                    element.ToolTipText = @"View/Modify " + myStation + " Profile and Current Configuration";
                    element.Enabled = true;
                    element.DisplayStyle = DisplayStyle.Image;
                    element.ShowBorder = true;
                }
                else
                {
                    element.Enabled = false;
                    element.DisplayStyle = DisplayStyle.None;
                    element.ShowBorder = false;
                }
                if (element.ElementState == ElementState.Constructed)
                    element.Click += new EventHandler(Workstation_Click);
 
            }
         }
     }
    catch (Exception ex)
    {
        RadMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, RadMessageIcon.Error);
    }
}

Other than the Telerik update - nothing else has changed.

Any help you could provide would be greatly appreciated.  This is extremely urgent as I will be demoing this product early next week.

thanks!


Note:  I am using 4 different themes: Office2010Blue, Black and Silver and Windows7.  All themes show same behavior.

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 31 Jul 2012, 01:07 PM
Hi Path,

Thank you for writing.

In our latest release, we introduced a new functionality of GridViewCommandColumn - an Image property which will be the default image for all buttons in the column. The Image property of the button elements is bound to the Image property of the column and your local setting is overridden by the binding, which has higher priority. 

So you have two possibilities:
1. Set the image in the column's Image property if you want the same image everywhere
2. Unbind the Image property prior setting the image of the button in CellFormatting:
void grid_CellFormatting(object sender, CellFormattingEventArgs e)
       {
           if (e.CellElement is GridCommandCellElement)
           {
               if (e.Column.Name == "stationview")
               {
                   RadButtonElement element = (RadButtonElement)e.CellElement.Children[0];
                   element.UnbindProperty(RadButtonElement.ImageProperty);
                   element.Image = Image.FromFile(@"C:\Program Files (x86)\Telerik\RadControls for WinForms Q2 2012\Examples\QuickStart\Resources\2RibbonMenuOpen2.png");
                   element.DisplayStyle = DisplayStyle.Image;
                   element.ImageAlignment = ContentAlignment.MiddleCenter;
               }
           }
       }

Another thing I noticed is that you are making a check for header row in the CellFormatting event. You do not need to do so, since this event is fired only for data cells:
!(e.CellElement.RowElement is GridTableHeaderRowElement)

I hope this helps. 

Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Jason Parrish
Top achievements
Rank 1
answered on 31 Aug 2012, 03:18 PM
I do not see this listed as a breaking change on the latest release.
http://www.telerik.com/products/winforms/whats-new/release-history/q2-2012-sp1-version-2012-2-726.aspx 

I have been troubleshooting this for the past several days.  I also discovered that when attempting to set the Image property via the Property Builder dialog, I get an error  of "Object reference not set to an instance of an object."  See screenshot.

0
Stefan
Telerik team
answered on 03 Sep 2012, 02:29 PM
Hello,

Thank you Pat, we are aware of this case and we will address it in future release.
 
Regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Stefan
Telerik team
answered on 05 Sep 2012, 12:20 PM
Hello guys,

I just wanted to let you know that here is the PITS item for the initial issue in this thread, so feel free to add your votes for it: http://www.telerik.com/support/pits.aspx#/public/winforms/12569.
 
Regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Patrick Baggett
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Jason Parrish
Top achievements
Rank 1
Share this question
or