We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Image in GridControl cells

Thread ID:





26840 Apr 1,2005 10:14 AM UTC Apr 1,2005 02:23 PM UTC WinForms 4
Tags: GridControl
Administrator [Syncfusion]
Asked On April 1, 2005 10:14 AM UTC

Version In the uploaded sample application, I want to add the image as well as text in the grid control cells. I was able to add the image in static and textbox cell types, if I click on any of row header and select add image then image is not set for Header cells. I want to add the image on Pushbutton, Checkbox and Header cell types also. Kindly let me know any of possible solutions. Is there any property to set the image list for the whole grid control?

Administrator [Syncfusion]
Replied On April 1, 2005 10:18 AM UTC

Since the uploaded source link was not found, the source is here ******************** Source ****************** using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Collections.Specialized; using Syncfusion.Windows.Forms.Grid; namespace ImagePost { /// /// Summary description for mainFrom. /// public class mainFrom : System.Windows.Forms.Form { private Syncfusion.Windows.Forms.Grid.GridControl gcImageGrid; private System.Windows.Forms.ContextMenu ctexMenu; private System.Windows.Forms.ImageList imageList1; private System.Collections.Specialized.StringCollection choiceList; private System.ComponentModel.IContainer components; public mainFrom() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.gcImageGrid = new Syncfusion.Windows.Forms.Grid.GridControl(); ((System.ComponentModel.ISupportInitialize)(this.gcImageGrid)).BeginInit(); this.SuspendLayout(); // // gcImageGrid // this.gcImageGrid.Location = new System.Drawing.Point(0, 0); this.gcImageGrid.Name = "gcImageGrid"; this.gcImageGrid.Size = new System.Drawing.Size(816, 400); this.gcImageGrid.TabIndex = 0; this.gcImageGrid.Text = "ImageGrid"; // // mainFrom // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(840, 461); this.Controls.Add(this.gcImageGrid); this.Name = "mainFrom"; this.Text = "Test Form"; this.Load += new System.EventHandler(this.mainFrom_Load); ((System.ComponentModel.ISupportInitialize)(this.gcImageGrid)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new mainFrom()); } private void mainFrom_Load(object sender, System.EventArgs e) { //Add Context menu ctexMenu = new ContextMenu(); ctexMenu.MenuItems.Add(0, new MenuItem("Add Image", new EventHandler(this.AddImage_Click))); ctexMenu.MenuItems.Add(1, new MenuItem("Remove Image", new EventHandler(this.RemoveImage_Click))); gcImageGrid.ContextMenu = ctexMenu; imageList1 = new ImageList(); imageList1.Images.Add(SystemIcons.Question.ToBitmap()); choiceList = new StringCollection(); choiceList.Add("One"); choiceList.Add("Two"); choiceList.Add("Three"); this.gcImageGrid.RowCount = 5; this.gcImageGrid.ColCount = 3; //this.gcImageGrid.HideCols[0] = true; //Add static cell this.gcImageGrid[1,1].CellType = "Static"; this.gcImageGrid[1,1].Text = "Test"; //Add static readonly cell this.gcImageGrid[2,1].Text = "ReadOnly"; this.gcImageGrid[2,1].CellType = "Static"; this.gcImageGrid[2,1].ReadOnly = true; //Add Pushbutton this.gcImageGrid[3,1].CellType = "PushButton"; this.gcImageGrid[3,1].Description = "Push"; //Add Checkbox this.gcImageGrid[4,1].CellType = "CheckBox"; this.gcImageGrid[4,1].Description = "check"; //Add ComboBox this.gcImageGrid[5,1].CellType = "ComboBox"; this.gcImageGrid[5,1].ChoiceList = choiceList; for(int row = 1; row <= gcImageGrid.RowCount; row++) for(int i = 2; i <= gcImageGrid.ColCount; i++) { this.gcImageGrid[row, i].CellType = "TextBox"; this.gcImageGrid[row, i].Text = "Row "+row; } } private void AddImage_Click(object sender, EventArgs e) { int row = gcImageGrid.CurrentCell.RowIndex; int col = gcImageGrid.CurrentCell.ColIndex; bool readOnly = this.gcImageGrid.IgnoreReadOnly; //If some cells are Readonly ignore that readonly this.gcImageGrid.IgnoreReadOnly = true; GridStyleInfo cell = gcImageGrid[row, col]; cell.ImageList = imageList1; cell.ImageIndex = 0; this.gcImageGrid.IgnoreReadOnly = readOnly; } private void RemoveImage_Click(object sender, EventArgs e) { int row = gcImageGrid.CurrentCell.RowIndex; int col = gcImageGrid.CurrentCell.ColIndex; bool readOnly = this.gcImageGrid.IgnoreReadOnly; //If some cells are Readonly ignore that readonly this.gcImageGrid.IgnoreReadOnly = true; //gcImageGrid[row, col].ImageList = imageList1; gcImageGrid[row, col].ImageIndex = -1; this.gcImageGrid.IgnoreReadOnly = readOnly; } } }

Administrator [Syncfusion]
Replied On April 1, 2005 10:35 AM UTC

If you want to display images in arbitrary cell types, it probably will be simpler to handle the CellDrawn event, and just draw the image there after the grid has finished doing its default drawing. In the CellDrawn event, you can decorate the cell with custom drawing independent of the actual celltype. Here is a forum thread that shows how you can use this event to draw images in cells. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=16748

Administrator [Syncfusion]
Replied On April 1, 2005 01:26 PM UTC

Thanks Clay, It works well. Is there any option to change the back color instead of placing the image at runtime for those cells (Header, Static, and Push buttons and all types)? And it should have the provision for revert back to the original color which was set while loading the Grid.

Administrator [Syncfusion]
Replied On April 1, 2005 02:23 PM UTC

The BackColor of a cell is normally controlled through the style.BackColor property of the cell. This should work for any cell unless you are handling some event that prevents this default behavior. One comment though is that the backcolor of buttons is not control through the style object for the cell. Instead, you will have to handle an event to color buttons. Here is a forum thread discussing coloring buttons. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=26772


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon