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

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

5 Answers 244 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Surya
Top achievements
Rank 1
Surya asked on 08 Feb 2012, 07:55 PM
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.

5 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 09 Feb 2012, 10:38 AM
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
0
Surya
Top achievements
Rank 1
answered on 09 Feb 2012, 11:52 AM
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.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 09 Feb 2012, 12:51 PM
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

0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 09 Feb 2012, 12:56 PM
Also, based on what you are doing, you don't need the CellFormatting event currently.
Richard
0
Surya
Top achievements
Rank 1
answered on 09 Feb 2012, 01:31 PM
Hi ,

 Thanks for quick response. 

Solution provided by you is working.
Tags
GridView
Asked by
Surya
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Surya
Top achievements
Rank 1
Share this question
or