ComboBox in DataGrid, shows up but won't drop down when clicked.
-
I used Microsoft's way of adding a combobox to a datagrid by just adding a combobox to the datagrid's controls and moving it to the proper row and column when CurrentCellChanged is fired. http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q323167 This code they give is in VB.Net, and I assume it works because many people have used it (from reading on forums). However, when I converted it to C# it does not drop down when it is clicked. I do add it to the DataGrid.Controls and it is displayed. I do not think i should have to add events for clicking, the combo box is in the datagrid's controls and should receive the click event itself and drop down. If it works in VB.Net I can't see why it would be any different in C#. Has anyone ever done their example in C# and got it to work, I know I can make my own DataGridColumnStyle and i have found examples of it that work. But I really like the simplicity of Microsoft's way and the fact that I should be able to just add any control to the datagrid. Thanks for any help.
DataColumn editJobNameColumn = new DataColumn( "Job Name", typeof( string ) ); editJobNameColumn.AllowDBNull = false; editJobNameColumn.Unique = true; editJobNameColumn.DefaultValue = ""; DataColumn editJobRateColumn = new DataColumn( "Charge Rate", typeof( decimal ) ); editJobRateColumn.AllowDBNull = false; editJobRateColumn.DefaultValue = 0.0M; DataTable editJobsRates = new DataTable( "Jobs" ); editJobsRates.Columns.Add( editJobNameColumn ); editJobsRates.Columns.Add( editJobRateColumn ); dtvwEditJobs.Table = editJobsRates; this.dtgdEditJobs.DataSource = this.dtvwEditJobs; this.dtgdEditJobs.Click += new System.EventHandler(this.dtgdEditJobs_Click); this.dtgdEditJobs.CurrentCellChanged += new System.EventHandler(this.dtgdEditJobs_CurrentCellChanged); this.dtgdEditJobs.Paint += new System.Windows.Forms.PaintEventHandler(this.dtgdEditJobs_Paint); this.dtgdEditJobs.Scroll += new System.EventHandler(this.dtgdEditJobs_Scroll); private void dtgdEditJobs_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { if( dtgdEditJobs.CurrentCell.ColumnNumber == 0 ) { cmbEditJobs.Width = dtgdEditJobs.GetCurrentCellBounds().Width; } } private void dtgdEditJobs_Click(object sender, System.EventArgs e) { cmbEditJobs.Visible = false; cmbEditJobs.Width = 0; } private void dtgdEditJobs_Scroll(object sender, System.EventArgs e) { cmbEditJobs.Visible = false; cmbEditJobs.Width = 0; } private void dtgdEditJobs_CurrentCellChanged(object