Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WinForms: How to add any control to a DataGrid column

WinForms: How to add any control to a DataGrid column

Scheduled Pinned Locked Moved C#
csharpcsswpfwinformsgraphics
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SebbaP
    wrote on last edited by
    #1

    Hello, I have been trying to add a custom control to one of the columns in my DataGrid, but I have failed so far. What I want to do is to add my custom control (or any other standard control for that matter) to the control collection of a certain column style. When I do so, the control will not appear until I click on any of the cells, which is supposed to show the control. Is it even possible to add controls to the control collection of textbox column styles, considering what I want to do? If you have any ideas, please use my sample code below as a starting point and reply to me with a modified version of it. Also, I am curious to know what causes this kind of weird behaviour. I would have expected the button to appear right away, but that's obviously not the case :wtf:. Does anyone have extremely detailed knowledge about how and when controls are painted? I would like to know the exact chain of events that causes this behaviour and why. Thank you for your patience, I hope you can help!! (I wont settle for a workaround ;)) using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication2 { public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; DataGrid grid = new DataGrid(); DataTable table; public Form1() { InitializeComponent(); this.Controls.Add( this.grid ); // create the table this.table = new DataTable("A_Table"); this.table.Columns.Add( new DataColumn("TextColumn", typeof(string)) ); this.table.Columns.Add( new DataColumn("ButtonColumn", typeof(string)) ); // bind the table to the grid DataSet dataSet = new DataSet(); dataSet.Tables.Add( this.table ); this.grid.SetDataBinding(dataSet, "A_Table"); // set up column style... DataGridTableStyle tStyle = new DataGridTableStyle(); tStyle.MappingName = "A_Table"; // ...for the left column DataGridTextBoxColumn textStyle = new DataGridTextBoxColumn(); textStyle.MappingName = "TextColumn"; textStyle.HeaderText= table.Columns[0].Caption; textStyle.Width = 200; textStyle.ReadOnly = true; tStyle.GridColumnStyles.Add(textStyle); // ...for the right column textStyle = new DataGridTextBoxColumn(); textStyle.MappingName = "ButtonColumn"; textStyle.HeaderText= table.Columns[1].Captio

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups