button element images not showing in my gridview

5 posts, 0 answers
  1. Patrick Baggett
    Patrick Baggett avatar
    9 posts
    Member since:
    Aug 2012

    Posted 27 Jul 2012 Link to this post

    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.

  2. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 31 Jul 2012 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jason Parrish
    Jason Parrish avatar
    87 posts
    Member since:
    Sep 2009

    Posted 31 Aug 2012 Link to this post

    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.

  5. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 03 Sep 2012 Link to this post

    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 >>
  6. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 05 Sep 2012 Link to this post

    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 >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready