Click here to Skip to main content
15,891,657 members
Home / Discussions / C#
   

C#

 
GeneralRe: Program resolution is off Pin
PHDENG815-Aug-05 3:39
PHDENG815-Aug-05 3:39 
GeneralClearing database connections while using SQLHelper class Pin
Rashid_Mehmood5-Aug-05 2:58
Rashid_Mehmood5-Aug-05 2:58 
GeneralRe: Clearing database connections while using SQLHelper class Pin
Alomgir Miah5-Aug-05 4:01
Alomgir Miah5-Aug-05 4:01 
GeneralSuppress an Event Pin
zaboboa5-Aug-05 2:57
zaboboa5-Aug-05 2:57 
GeneralRe: Suppress an Event Pin
Pradyumna Gogte5-Aug-05 3:24
Pradyumna Gogte5-Aug-05 3:24 
GeneralRe: Suppress an Event Pin
Alomgir Miah5-Aug-05 3:54
Alomgir Miah5-Aug-05 3:54 
GeneralRe: Suppress an Event Pin
zaboboa5-Aug-05 4:50
zaboboa5-Aug-05 4:50 
GeneralWinForms: How to add any control to a DataGrid column Pin
SebbaP5-Aug-05 2:41
SebbaP5-Aug-05 2:41 
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 | :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 Wink | ;) )
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace WindowsApplication2<br />
{<br />
  public class Form1 : System.Windows.Forms.Form<br />
  {<br />
    private System.ComponentModel.Container components = null;<br />
<br />
    DataGrid grid = new DataGrid();<br />
    DataTable table;<br />
<br />
    public Form1()<br />
    {<br />
      InitializeComponent();<br />
<br />
      this.Controls.Add( this.grid );<br />
<br />
      // create the table<br />
      this.table = new DataTable("A_Table");<br />
      this.table.Columns.Add( new DataColumn("TextColumn", typeof(string)) );<br />
      this.table.Columns.Add( new DataColumn("ButtonColumn", typeof(string)) );<br />
<br />
      // bind the table to the grid<br />
      DataSet dataSet = new DataSet();<br />
      dataSet.Tables.Add( this.table );<br />
      this.grid.SetDataBinding(dataSet, "A_Table");<br />
<br />
      // set up column style...<br />
      DataGridTableStyle tStyle = new DataGridTableStyle();<br />
      tStyle.MappingName = "A_Table";<br />
      // ...for the left column<br />
      DataGridTextBoxColumn textStyle = new DataGridTextBoxColumn();<br />
      textStyle.MappingName = "TextColumn";<br />
      textStyle.HeaderText= table.Columns[0].Caption;<br />
      textStyle.Width = 200;<br />
      textStyle.ReadOnly = true;<br />
      tStyle.GridColumnStyles.Add(textStyle);<br />
		<br />
      // ...for the right column<br />
      textStyle = new DataGridTextBoxColumn();<br />
      textStyle.MappingName = "ButtonColumn";<br />
      textStyle.HeaderText= table.Columns[1].Caption;<br />
      textStyle.Width = 80;<br />
      textStyle.ReadOnly = true;<br />
<br />
      // add a bytton to the right column's control collection<br />
      Button b = new Button();<br />
      b.Text = "OK";<br />
      b.Dock = DockStyle.Fill;<br />
      textStyle.TextBox.Controls.Add( b );<br />
      tStyle.GridColumnStyles.Add(textStyle);<br />
			<br />
      // set size and location of grid<br />
      tStyle.PreferredRowHeight = 20;<br />
      this.grid.TableStyles.Add(tStyle);<br />
      this.grid.Location = new Point(10, 10);<br />
      this.grid.Size = new Size(400, 100);<br />
			<br />
      // set size of form<br />
      this.Width = 420;<br />
      this.Height = 200;<br />
			<br />
      // add some data to the table<br />
      DataRow row = table.NewRow();<br />
      row[0] = "There should be a button to the right";<br />
      row[1] = "";<br />
      table.Rows.Add(row);<br />
    }<br />
<br />
    protected override void Dispose( bool disposing )<br />
    {<br />
      if( disposing )<br />
      {<br />
        if (components != null) <br />
        {<br />
           components.Dispose();<br />
        }<br />
      }<br />
      base.Dispose( disposing );<br />
    }<br />
<br />
    private void InitializeComponent()<br />
    {<br />
      this.components = new System.ComponentModel.Container();<br />
      this.Size = new System.Drawing.Size(300,300);<br />
      this.Text = "Form1";<br />
    }<br />
<br />
    [STAThread]<br />
    static void Main() <br />
    {<br />
      Application.Run(new Form1());<br />
    }<br />
  }<br />
}<br />

GeneralTab control Pin
deep75-Aug-05 2:26
deep75-Aug-05 2:26 
GeneralRe: Tab control Pin
Alomgir Miah5-Aug-05 3:58
Alomgir Miah5-Aug-05 3:58 
GeneralNeed help with a data set problem.. Pin
corkey195-Aug-05 1:38
corkey195-Aug-05 1:38 
QuestionHow do we List Down All User Names and Passwords in SQL Server? Pin
pubududilena5-Aug-05 1:24
pubududilena5-Aug-05 1:24 
AnswerRe: How do we List Down All User Names and Passwords in SQL Server? Pin
Dave Kreskowiak5-Aug-05 4:50
mveDave Kreskowiak5-Aug-05 4:50 
GeneralLoop through combobox items Pin
fady_sayegh5-Aug-05 0:06
fady_sayegh5-Aug-05 0:06 
GeneralRe: Loop through combobox items Pin
Pradyumna Gogte5-Aug-05 0:20
Pradyumna Gogte5-Aug-05 0:20 
GeneralRe: Loop through combobox items Pin
Guffa5-Aug-05 0:21
Guffa5-Aug-05 0:21 
GeneralRe: Loop through combobox items Pin
fady_sayegh5-Aug-05 0:29
fady_sayegh5-Aug-05 0:29 
GeneralRe: Loop through combobox items Pin
Guffa5-Aug-05 4:43
Guffa5-Aug-05 4:43 
Generalcapturing the right click and paste mouse events Pin
pjoseph9994-Aug-05 23:33
pjoseph9994-Aug-05 23:33 
General.net equivalent of ddx + q about anchoring Pin
roel_4-Aug-05 22:58
roel_4-Aug-05 22:58 
GeneralRe: .net equivalent of ddx + q about anchoring Pin
Pradyumna Gogte5-Aug-05 0:17
Pradyumna Gogte5-Aug-05 0:17 
GeneralRe: .net equivalent of ddx + q about anchoring Pin
roel_5-Aug-05 1:17
roel_5-Aug-05 1:17 
GeneralRe: .net equivalent of ddx + q about anchoring Pin
Pradyumna Gogte5-Aug-05 2:01
Pradyumna Gogte5-Aug-05 2:01 
GeneralRe: .net equivalent of ddx + q about anchoring Pin
Dan Neely5-Aug-05 2:04
Dan Neely5-Aug-05 2:04 
Questionhow to define length of double dimension array Pin
Anonymous4-Aug-05 22:48
Anonymous4-Aug-05 22:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.