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. Image for the cookie policy date

Virtual Grid ComboBox CellType

Hello. I''m facing the following problem : I have implemented a virtual DataGrid. I have defined into the QueryCellInfo handler that e.CellType="ComboBox" e.ValueType=typeof(string) when Im editing the edit portion of the ComboBox everything works fine, but when Im choosing among several options of the ComboBox''s dropdownlist then the edit portion is not updated (so the underlying dataset). 2. When I define int the ColStyles the following ColStyles[4].CellType="ComboBox"; ColStyles[4].Datasource=adatasource; COlStyles[4].DisplayMember="atable.afield"; the list portion of the combobox remains empty; Do you have any idea what is happening?

5 Replies

AD Administrator Syncfusion Team December 20, 2004 09:42 AM

This is a GridControl, correct? Try this code. ColStyles[4].CellType = "ComboBox" ColStyles[4].Datasource = adatasource.Tables["atable"]; ColStyles[4].DisplayMember = "afield"; ColStyles[4].ValueMember = "afield";


SI simos December 21, 2004 01:15 AM

>This is a GridControl, correct? >Try this code. > >ColStyles[4].CellType = "ComboBox" >ColStyles[4].Datasource = adatasource.Tables["atable"]; >ColStyles[4].DisplayMember = "afield"; >ColStyles[4].ValueMember = "afield"; > > > Still the same problem. Furthermore I''ve noticed that the selection bar of the cell''s combobox is trapped into the first option when i try to use down arrow. Is there any clue? Thank you very much Clay :)


AD Administrator Syncfusion Team December 21, 2004 05:18 AM

Here is a sample that seems to work OK for me using 2.1.0.9. What are you doing differently? http://64.78.18.34/Support/Forums/Uploads/GC_Virt_Combo.zip


SI simos December 23, 2004 01:04 AM

>Here is a sample that seems to work OK for me using 2.1.0.9. What are you doing differently? > >http://64.78.18.34/Support/Forums/Uploads/GC_Virt_Combo.zip Im using Evaluation Essential Suite 3. I got read of a Handled=true; inside GridQueryCellInfoEventHandler so the Combo works fine. But still I have to put DataSource ,DisplayMember ,ValueMember for combo into GridQueryCellInfoEventHandler using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Syncfusion.Windows.Forms.Grid; namespace TestSyncFusion { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private Syncfusion.Windows.Forms.Grid.GridControl gridTest; private TestSyncFusion.ds_test ds_test1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private System.Windows.Forms.TextBox tb_aname; private System.Windows.Forms.TextBox tb_anumber; private System.Windows.Forms.Button bt_new; private System.Windows.Forms.Button bt_save; private CurrencyManager cm; private DataSet ds_combotest; #region SaveCellInfo //handler - needed if you are editing //save the changes back to the datasource private void GridSaveCellInfo(object sender, GridSaveCellInfoEventArgs e) { try { //move the changes back to the external data object if( e.ColIndex > 0 && e.RowIndex > 0) { (this.cm.Current as DataRowView)[e.ColIndex-1]=e.Style.Text; (this.cm.Current as DataRowView).EndEdit(); } } catch(Exception e1){ MessageBox.Show(e1.Message); } e.Handled = true; } #endregion #region Required Handlers //provide the row count from the datasource void GridQueryRowCount(object sender, GridRowColCountEventArgs e) { if (cm==null) {e.Count=0;return;} e.Count = this.cm.Count; e.Handled = true; } //provide the column count from the datasource void GridQueryColCount(object sender, GridRowColCountEventArgs e) { e.Count = this.ds_test1.Tables[0].Columns.Count; e.Handled = true; } //provide the data from the datasource void GridQueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if (e.RowIndex > 0 && e.ColIndex > 0) { #region COMMENT_ME if (e.ColIndex==4) { e.Style.CellType="ComboBox"; e.Style.CellValue=typeof(string); e.Style.DataSource=this.ds_combotest.Tables[0]; e.Style.DisplayMember="TESTVALUE2"; } #endregion e.Style.CellValue = (this.cm.List[e.RowIndex - 1] as DataRowView)[e.ColIndex-1]; } } #endregion #region Optional Handlers //provide the row heights on demand - optional... void GridQueryRowHeight(object sender, GridRowColSizeEventArgs e) { if( e.Index % 2 == 0) { e.Size = 20; e.Handled = true; } } //provide the col widths on demand - optional... void GridQueryColWidth(object sender, GridRowColSizeEventArgs e) { if( e.Index % 3 == 0) { e.Size = 40; e.Handled = true; } } //provide covered range on demand - optional... void GridQueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e) { //cover odd rows, columns 1 through 3 if (e.RowIndex % 2 == 1 && e.ColIndex >= 1 && e.ColIndex <= 3) { e.Range = GridRangeInfo.Cells(e.RowIndex, 1, e.RowIndex, 3); e.Handled = true; } //cover column 6 with odd-even row pairs if (e.RowIndex > 0 && e.ColIndex == 6) { int row = (e.RowIndex-1) /2 * 2 + 1; int col = e.ColIndex; e.Range = GridRangeInfo.Cells(row, col, row+1, col); e.Handled = true; } } #endregion public Form1() { // // Required for Windows Form Designer support // this.ds_combotest=new DataSet(); InitializeComponent(); this.gridTest.ResetVolatileData(); gridTest.QueryCellInfo += new GridQueryCellInfoEventHandler(GridQueryCellInfo); gridTest.QueryRowCount += new GridRowColCountEventHandler(GridQueryRowCount); gridTest.QueryColCount += new GridRowColCountEventHandler(GridQueryColCount); //if you want to edit your data in the grid, you need to //handle saving data back to the data source... gridTest.SaveCellInfo += new GridSaveCellInfoEventHandler(GridSaveCellInfo); this.ds_combotest.Tables.Add("COMBOTEST"); this.ds_combotest.Tables[0].Columns.Add("TESTVALUE1",typeof(int)); this.ds_combotest.Tables[0].Columns.Add("TESTVALUE2",typeof(string)); for(int i=0;i<50;i++) { DataRow dr=this.ds_combotest.Tables[0].NewRow(); dr["TESTVALUE1"]=(int) i; dr["TESTVALUE2"]="New Row "+i.ToString(); this.ds_combotest.Tables[0].Rows.Add(dr); } this.ds_combotest.Tables[0].AcceptChanges(); // // 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.gridTest = new Syncfusion.Windows.Forms.Grid.GridControl(); this.ds_test1 = new TestSyncFusion.ds_test(); this.tb_aname = new System.Windows.Forms.TextBox(); this.tb_anumber = new System.Windows.Forms.TextBox(); this.bt_new = new System.Windows.Forms.Button(); this.bt_save = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.gridTest)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ds_test1)).BeginInit(); this.SuspendLayout(); // // gridTest // this.gridTest.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192))); this.gridTest.ColWidthEntries.AddRange(new Syncfusion.Windows.Forms.Grid.GridColWidth[] { new Syncfusion.Windows.Forms.Grid.GridColWidth(0, 35)}); this.gridTest.Location = new System.Drawing.Point(72, 120); this.gridTest.Name = "gridTest"; this.gridTest.Size = new System.Drawing.Size(320, 96); this.gridTest.SmartSizeBox = false; this.gridTest.TabIndex = 1; this.gridTest.Text = "gridControl1"; this.gridTest.CurrentCellActivated += new System.EventHandler(this.gridTest_CurrentCellActivated); // // ds_test1 // this.ds_test1.DataSetName = "ds_test"; this.ds_test1.Locale = new System.Globalization.CultureInfo("en-US"); // // tb_aname // this.tb_aname.Location = new System.Drawing.Point(72, 24); this.tb_aname.Name = "tb_aname"; this.tb_aname.Size = new System.Drawing.Size(416, 20); this.tb_aname.TabIndex = 2; this.tb_aname.Text = ""; // // tb_anumber // this.tb_anumber.Location = new System.Drawing.Point(72, 56); this.tb_anumber.Name = "tb_anumber"; this.tb_anumber.Size = new System.Drawing.Size(200, 20); this.tb_anumber.TabIndex = 3; this.tb_anumber.Text = ""; // // bt_new // this.bt_new.Location = new System.Drawing.Point(416, 56); this.bt_new.Name = "bt_new"; this.bt_new.Size = new System.Drawing.Size(72, 24); this.bt_new.TabIndex = 5; this.bt_new.Text = "&New"; this.bt_new.Click += new System.EventHandler(this.bt_new_Click); // // bt_save // this.bt_save.Location = new System.Drawing.Point(416, 96); this.bt_save.Name = "bt_save"; this.bt_save.Size = new System.Drawing.Size(72, 24); this.bt_save.TabIndex = 6; this.bt_save.Text = "&Save"; this.bt_save.Click += new System.EventHandler(this.bt_save_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(576, 242); this.Controls.Add(this.bt_save); this.Controls.Add(this.bt_new); this.Controls.Add(this.tb_anumber); this.Controls.Add(this.tb_aname); this.Controls.Add(this.gridTest); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.gridTest)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.ds_test1)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { cm=(CurrencyManager)this.BindingContext[this.ds_test1,"TEST"]; this.tb_anumber.DataBindings.Add("Text",this.ds_test1,"TEST.ANUMBER"); this.tb_aname.DataBindings.Add("Text",this.ds_test1,"TEST.ASTRING"); this.gridTest.Model.ColStyles[1].CellValueType=typeof(string); this.gridTest.Model.ColStyles[3].CellValueType=typeof(float); this.gridTest.Model.ColStyles[4].CellValueType=typeof(string); #region UNCOMMENT_ME /* this.gridTest.Model.ColStyles[4].CellType="ComboBox"; this.gridTest.Model.ColStyles[4].DataSource=this.ds_combotest.Tables[0]; this.gridTest.Model.ColStyles[4].DisplayMember="TESTVALUE2"; this.gridTest.Model.ColStyles[4].ValueMember="TESTVALUE2"; */ #endregion } private void bt_new_Click(object sender, System.EventArgs e) { this.cm.AddNew(); this.tb_aname.Focus(); } private void bt_save_Click(object sender, System.EventArgs e) { (this.cm.Current as DataRowView).EndEdit(); (this.cm.Current as DataRowView).Row.AcceptChanges(); this.gridTest.Refresh(); } private void gridTest_CurrentCellActivated(object sender, System.EventArgs e) { this.cm.Position=this.gridTest.CurrentCell.RowIndex-1; } } }


AD Administrator Syncfusion Team June 16, 2005 09:32 PM

> > >>Here is a sample that seems to work OK for me using 2.1.0.9. What are you doing differently? >> >>http://64.78.18.34/Support/Forums/Uploads/GC_Virt_Combo.zip > > >Im using Evaluation Essential Suite 3. >I got read of a Handled=true; >inside GridQueryCellInfoEventHandler >so the Combo works fine. > >But still I have to put >DataSource ,DisplayMember ,ValueMember for combo >into GridQueryCellInfoEventHandler > > > > >using System; >using System.Drawing; >using System.Collections; >using System.ComponentModel; >using System.Windows.Forms; >using System.Data; >using Syncfusion.Windows.Forms.Grid; > >namespace TestSyncFusion >{ > /// > /// Summary description for Form1. > /// > public class Form1 : System.Windows.Forms.Form > { > private Syncfusion.Windows.Forms.Grid.GridControl gridTest; > private TestSyncFusion.ds_test ds_test1; > /// > /// Required designer variable. > /// > private System.ComponentModel.Container components = null; > private System.Windows.Forms.TextBox tb_aname; > private System.Windows.Forms.TextBox tb_anumber; > private System.Windows.Forms.Button bt_new; > private System.Windows.Forms.Button bt_save; > > private CurrencyManager cm; > > private DataSet ds_combotest; > > > > > #region SaveCellInfo //handler - needed if you are editing > //save the changes back to the datasource > private void GridSaveCellInfo(object sender, GridSaveCellInfoEventArgs e) > { > try > { > //move the changes back to the external data object > if( e.ColIndex > 0 && e.RowIndex > 0) > { > (this.cm.Current as DataRowView)[e.ColIndex-1]=e.Style.Text; > (this.cm.Current as DataRowView).EndEdit(); > > } > } > catch(Exception e1){ > MessageBox.Show(e1.Message); > } > e.Handled = true; > } > #endregion > > #region Required Handlers > //provide the row count from the datasource > void GridQueryRowCount(object sender, GridRowColCountEventArgs e) > { > if (cm==null) > {e.Count=0;return;} > e.Count = this.cm.Count; > e.Handled = true; > } > > > //provide the column count from the datasource > void GridQueryColCount(object sender, GridRowColCountEventArgs e) > { > e.Count = this.ds_test1.Tables[0].Columns.Count; > e.Handled = true; > } > > > //provide the data from the datasource > void GridQueryCellInfo(object sender, GridQueryCellInfoEventArgs e) > { > if (e.RowIndex > 0 && e.ColIndex > 0) > { > > #region COMMENT_ME > if (e.ColIndex==4) > { > e.Style.CellType="ComboBox"; > e.Style.CellValue=typeof(string); > e.Style.DataSource=this.ds_combotest.Tables[0]; > e.Style.DisplayMember="TESTVALUE2"; > } > #endregion > > e.Style.CellValue = (this.cm.List[e.RowIndex - 1] as DataRowView)[e.ColIndex-1]; > } > } > > #endregion > > #region Optional Handlers > //provide the row heights on demand - optional... > void GridQueryRowHeight(object sender, GridRowColSizeEventArgs e) > { > if( e.Index % 2 == 0) > { > e.Size = 20; > e.Handled = true; > } > } > > > //provide the col widths on demand - optional... > void GridQueryColWidth(object sender, GridRowColSizeEventArgs e) > { > if( e.Index % 3 == 0) > { > e.Size = 40; > e.Handled = true; > } > } > > > //provide covered range on demand - optional... > void GridQueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e) > { > //cover odd rows, columns 1 through 3 > if (e.RowIndex % 2 == 1 && e.ColIndex >= 1 && e.ColIndex <= 3) > { > e.Range = GridRangeInfo.Cells(e.RowIndex, 1, e.RowIndex, 3); > e.Handled = true; > } > > //cover column 6 with odd-even row pairs > if (e.RowIndex > 0 && e.ColIndex == 6) > { > int row = (e.RowIndex-1) /2 * 2 + 1; > int col = e.ColIndex; > e.Range = GridRangeInfo.Cells(row, col, row+1, col); > e.Handled = true; > } > } > > #endregion > > > > public Form1() > { > // > // Required for Windows Form Designer support > // > this.ds_combotest=new DataSet(); > > InitializeComponent(); > this.gridTest.ResetVolatileData(); > > gridTest.QueryCellInfo += new GridQueryCellInfoEventHandler(GridQueryCellInfo); > gridTest.QueryRowCount += new GridRowColCountEventHandler(GridQueryRowCount); > gridTest.QueryColCount += new GridRowColCountEventHandler(GridQueryColCount); > > //if you want to edit your data in the grid, you need to > //handle saving data back to the data source... > gridTest.SaveCellInfo += new GridSaveCellInfoEventHandler(GridSaveCellInfo); > > > this.ds_combotest.Tables.Add("COMBOTEST"); > this.ds_combotest.Tables[0].Columns.Add("TESTVALUE1",typeof(int)); > this.ds_combotest.Tables[0].Columns.Add("TESTVALUE2",typeof(string)); > > > for(int i=0;i<50;i++) > { > DataRow dr=this.ds_combotest.Tables[0].NewRow(); > dr["TESTVALUE1"]=(int) i; > dr["TESTVALUE2"]="New Row "+i.ToString(); > this.ds_combotest.Tables[0].Rows.Add(dr); > > > > > } > > this.ds_combotest.Tables[0].AcceptChanges(); > > > > // > // 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.gridTest = new Syncfusion.Windows.Forms.Grid.GridControl(); > this.ds_test1 = new TestSyncFusion.ds_test(); > this.tb_aname = new System.Windows.Forms.TextBox(); > this.tb_anumber = new System.Windows.Forms.TextBox(); > this.bt_new = new System.Windows.Forms.Button(); > this.bt_save = new System.Windows.Forms.Button(); > ((System.ComponentModel.ISupportInitialize)(this.gridTest)).BeginInit(); > ((System.ComponentModel.ISupportInitialize)(this.ds_test1)).BeginInit(); > this.SuspendLayout(); > // > // gridTest > // > this.gridTest.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192))); > this.gridTest.ColWidthEntries.AddRange(new Syncfusion.Windows.Forms.Grid.GridColWidth[] { > new Syncfusion.Windows.Forms.Grid.GridColWidth(0, 35)}); > this.gridTest.Location = new System.Drawing.Point(72, 120); > this.gridTest.Name = "gridTest"; > this.gridTest.Size = new System.Drawing.Size(320, 96); > this.gridTest.SmartSizeBox = false; > this.gridTest.TabIndex = 1; > this.gridTest.Text = "gridControl1"; > this.gridTest.CurrentCellActivated += new System.EventHandler(this.gridTest_CurrentCellActivated); > // > // ds_test1 > // > this.ds_test1.DataSetName = "ds_test"; > this.ds_test1.Locale = new System.Globalization.CultureInfo("en-US"); > // > // tb_aname > // > this.tb_aname.Location = new System.Drawing.Point(72, 24); > this.tb_aname.Name = "tb_aname"; > this.tb_aname.Size = new System.Drawing.Size(416, 20); > this.tb_aname.TabIndex = 2; > this.tb_aname.Text = ""; > // > // tb_anumber > // > this.tb_anumber.Location = new System.Drawing.Point(72, 56); > this.tb_anumber.Name = "tb_anumber"; > this.tb_anumber.Size = new System.Drawing.Size(200, 20); > this.tb_anumber.TabIndex = 3; > this.tb_anumber.Text = ""; > // > // bt_new > // > this.bt_new.Location = new System.Drawing.Point(416, 56); > this.bt_new.Name = "bt_new"; > this.bt_new.Size = new System.Drawing.Size(72, 24); > this.bt_new.TabIndex = 5; > this.bt_new.Text = "&New"; > this.bt_new.Click += new System.EventHandler(this.bt_new_Click); > // > // bt_save > // > this.bt_save.Location = new System.Drawing.Point(416, 96); > this.bt_save.Name = "bt_save"; > this.bt_save.Size = new System.Drawing.Size(72, 24); > this.bt_save.TabIndex = 6; > this.bt_save.Text = "&Save"; > this.bt_save.Click += new System.EventHandler(this.bt_save_Click); > // > // Form1 > // > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); > this.ClientSize = new System.Drawing.Size(576, 242); > this.Controls.Add(this.bt_save); > this.Controls.Add(this.bt_new); > this.Controls.Add(this.tb_anumber); > this.Controls.Add(this.tb_aname); > this.Controls.Add(this.gridTest); > this.Name = "Form1"; > this.Text = "Form1"; > this.Load += new System.EventHandler(this.Form1_Load); > ((System.ComponentModel.ISupportInitialize)(this.gridTest)).EndInit(); > ((System.ComponentModel.ISupportInitialize)(this.ds_test1)).EndInit(); > this.ResumeLayout(false); > > } > #endregion > > /// > /// The main entry point for the application. > /// > [STAThread] > static void Main() > { > Application.Run(new Form1()); > } > > private void Form1_Load(object sender, System.EventArgs e) > { > cm=(CurrencyManager)this.BindingContext[this.ds_test1,"TEST"]; > > > > > this.tb_anumber.DataBindings.Add("Text",this.ds_test1,"TEST.ANUMBER"); > this.tb_aname.DataBindings.Add("Text",this.ds_test1,"TEST.ASTRING"); > > > this.gridTest.Model.ColStyles[1].CellValueType=typeof(string); > > this.gridTest.Model.ColStyles[3].CellValueType=typeof(float); > this.gridTest.Model.ColStyles[4].CellValueType=typeof(string); > > > #region UNCOMMENT_ME > /* > this.gridTest.Model.ColStyles[4].CellType="ComboBox"; > this.gridTest.Model.ColStyles[4].DataSource=this.ds_combotest.Tables[0]; > this.gridTest.Model.ColStyles[4].DisplayMember="TESTVALUE2"; > this.gridTest.Model.ColStyles[4].ValueMember="TESTVALUE2"; > */ > #endregion > > > > > } > > private void bt_new_Click(object sender, System.EventArgs e) > { > this.cm.AddNew(); > this.tb_aname.Focus(); > } > > private void bt_save_Click(object sender, System.EventArgs e) > { > (this.cm.Current as DataRowView).EndEdit(); > (this.cm.Current as DataRowView).Row.AcceptChanges(); > this.gridTest.Refresh(); > > > } > > > private void gridTest_CurrentCellActivated(object sender, System.EventArgs e) > { > this.cm.Position=this.gridTest.CurrentCell.RowIndex-1; > } > > > > } > > > > >}

Loader.
Live Chat Icon For mobile
Up arrow icon