Need Edit , delete images in Grid View like Asp grid view in web Application

6 posts, 2 answers
  1. Surya
    Surya avatar
    41 posts
    Member since:
    Nov 2011

    Posted 08 Feb 2012 Link to this post

    Hi,

      I am working on Rad Win forms. I need edit and delete images in Rad Gridview Control like asp grid in web page.
    I had gone through following link 
    http://www.telerik.com/community/forums/winforms/gridview/show-mulitple-images-in-a-gridview-column.aspx 

    After scrolling , CustomGridDataCell is applying to  remaining columns.

     Please see attached Images.

    Thanks.
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 09 Feb 2012 Link to this post

    Hello Surya,

    It sounds as though from your code you are not resetting the LightVisualElement in the CellFormatting event. Because of the UI Virtualization model that the RadGridView uses, you will need to do this. Please take a look at this help topic on formatting cells which will show you how to reset the LightVisualElement.

    If this answers your question, please remember to mark as answer. If you need further help, please let me know
    Thanks
    Richard
  3. Surya
    Surya avatar
    41 posts
    Member since:
    Nov 2011

    Posted 09 Feb 2012 Link to this post

    Hi ,

     Thanks for quick response.

     I tried Cell formatting event , but still my problem exists.

    Please find check below code :

    CustomCell  

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.WinControls.Layouts;
    using Telerik.WinControls.UI;
    using System.Drawing;


    namespace SampleApplication
    {
        public class CustomCell : GridDataCellElement
        {
            private StackLayoutPanel panel = null;


            public CustomCell(GridViewColumn column, GridRowElement row)
                : base(column, row)
            {


            }


            protected override void CreateChildElements()
            {            
                base.CreateChildElements();
                this.panel = new StackLayoutPanel();
                this.panel.Orientation = System.Windows.Forms.Orientation.Horizontal;
                this.panel.StretchHorizontally = true;
                this.panel.StretchVertically = true;


                RadImageButtonElement button = new RadImageButtonElement();            
                button.Image = global::SampleApplication.Properties.Resources.edit;
                this.Children.Add(button);


                RadImageButtonElement button1 = new RadImageButtonElement();            
                button1.Image = global::SampleApplication.Properties.Resources.delete;
                this.Children.Add(button1);
            }




            public override bool IsEditable
            {
                get { return false; }
            }


            protected override SizeF ArrangeOverride(SizeF finalSize)
            {
                RectangleF clientRect = this.GetClientRectangle(finalSize);
                float buttonWidth = clientRect.Size.Width / this.Children.Count;
                RectangleF buttonFinalRect = new RectangleF(clientRect.Location, new SizeF(buttonWidth, clientRect.Height));


                foreach (RadButtonElement button in this.Children)
                {
                    button.Arrange(buttonFinalRect);
                    buttonFinalRect = new RectangleF(new PointF(buttonFinalRect.X + buttonWidth, buttonFinalRect.Y), buttonFinalRect.Size);
                }


                return finalSize;
            }
        }
    }

    Form1 .cs 

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
    using Telerik.WinControls;


    namespace SampleApplication
    {
        public partial class Form1 : RadForm
        {
            public Form1()
            {
                InitializeComponent();
            }


            private void Form1_Load(object sender, EventArgs e)
            {
                GridViewCommandColumn commandColumn = new GridViewCommandColumn("Actions");
                commandColumn.Name = "actions";
                commandColumn.AllowSort = commandColumn.AllowFiltering = commandColumn.AllowGroup = commandColumn.AllowResize = false;
                this.radGridView1.Columns.Add(commandColumn);




                DataTable objdt = new DataTable("testdata");
                objdt.Columns.Add("Slno", typeof(int));
                objdt.Columns.Add("Name", typeof(string));
                for (int i = 0; i < 100; i++)
                {
                    DataRow objdr = objdt.NewRow();
                    objdr[0] = i;
                    objdr[1] = "Test --" + i;
                    objdt.Rows.Add(objdr);
                }
                this.radGridView1.DataSource = objdt;
            }


            private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
            {
                GridViewCommandColumn dataColumn = e.Column as GridViewCommandColumn;
                if (e.Row is GridDataRowElement && dataColumn != null && dataColumn.Name == "actions")
                {               
                    CustomCell cell = new CustomCell(e.Column, e.Row);
                    e.CellElement = cell;
                }
            }

     private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
            {
                e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
            }

           


        }
    }




    Thanks.
  4. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 09 Feb 2012 Link to this post

    Hello,

    After looking at your code, it looks like you are missing the IsCompatible method that should be placed in your CustomGridDataCell class.

    public override bool IsCompatible(GridViewColumn data, object context)
    {
        return data is GridViewCommandColumn && context is GridDataRowElement;
    }

    Also I'd suggest having a look at this help topic as the information you were taking your sample from is a little out of date.

    Hope that helps
    Richard

  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 09 Feb 2012 Link to this post

    Also, based on what you are doing, you don't need the CellFormatting event currently.
    Richard
  6. Surya
    Surya avatar
    41 posts
    Member since:
    Nov 2011

    Posted 09 Feb 2012 Link to this post

    Hi ,

     Thanks for quick response. 

    Solution provided by you is working.
Back to Top