Resize datagrid problem in Winforms

Hi, I have a custom built DataGrid (Winforms) to which I have added menus for sort, find, hide columns etc. In one of the columns I have inherited DataGridTextBoxColumn and overriden methods to show ComboBox. When I load the datagrid I have no issues. But when I hide a column and then resize or click on the combobox column(Inherited using DataGridTextBoxColumn) it gives me an error saying An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll '375' is not a valid value for 'value'. 'value' should be between 'minimum' and 'maximum'. Can someone please help. This happens only when I hide a column. I am setting the size of the column to 0 when I do this. Please find below the code I use to hidecolumns and bind the currentstyle to datagrid. private void HideColumns(object sender, System.EventArgs e) { try { MenuItem mnuit; CurrencyManager cm = (CurrencyManager) this.BindingContext[this.DataSource,this.DataMember]; IList lists = cm.List; ITypedList iType = (ITypedList) lists; string stylename = iType.GetListName(null); DataGridTableStyle dtStyle = this.TableStyles[stylename]; if(!this.mnuHidden.Enabled) {mnuHidden.Enabled =true;} if(dtView==null) {BindDefualtDataMember();} //Add new menu to this menu as child mnuit = new MenuItem(dtView.Table.Columns[intSelectedCol+1].ColumnName, new System.EventHandler(enableSubMenus) ); int mnuCount=this.mnuHidden.MenuItems.Count; if(mnuCount > 0) { this.mnuHidden.MenuItems.Add(this.mnuHidden.MenuItems.Count,mnuit); htable.Add(mnuCount, this.TableStyles[stylename].GridColumnStyles[intSelectedCol].Width); } else { this.mnuHidden.MenuItems.Add(0,mnuit); htable.Add(mnuCount, this.TableStyles[stylename].GridColumnStyles[intSelectedCol].Width); } dtStyle.GridColumnStyles[intSelectedCol].Width = 0; Invalidate(); this.TableStyles.Add(dtStyle); } catch(Exception ex) { //Do nothing MessageBox.Show(ex.Message); } } private void BindDefualtDataMember() { BindingManagerBase cm = this.BindingContext[this.DataSource,this.DataMember] ; DataRowView drv =(DataRowView) cm.Current ; DataTable dt = drv.Row.Table ; dtView = dt.DefaultView; }

1 Reply

AN André February 17, 2004 04:59 PM UTC

I had a simular problem. I managed to solve it by set the column width to 1 instead of 0. It gives at least a hint of where the problem is located. /André > Hi, > > I have a custom built DataGrid (Winforms) to which I have added menus for sort, find, hide columns etc. In one of the columns I have inherited DataGridTextBoxColumn and overriden methods to show ComboBox. > > When I load the datagrid I have no issues. But when I hide a column and then resize or click on the combobox column(Inherited using DataGridTextBoxColumn) it gives me an error saying > > An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll > > '375' is not a valid value for 'value'. 'value' should be between 'minimum' and 'maximum'. > > > Can someone please help. This happens only when I hide a column. I am setting the size of the column to 0 when I do this. > > Please find below the code I use to hidecolumns and bind the currentstyle to datagrid. > > private void HideColumns(object sender, System.EventArgs e) > > { > > > try > > { > > MenuItem mnuit; > > CurrencyManager cm = (CurrencyManager) this.BindingContext[this.DataSource,this.DataMember]; > > IList lists = cm.List; > > ITypedList iType = (ITypedList) lists; > > string stylename = iType.GetListName(null); > > DataGridTableStyle dtStyle = this.TableStyles[stylename]; > > if(!this.mnuHidden.Enabled) > > {mnuHidden.Enabled =true;} > > > > if(dtView==null) > > {BindDefualtDataMember();} > > //Add new menu to this menu as child > > > mnuit = new MenuItem(dtView.Table.Columns[intSelectedCol+1].ColumnName, new System.EventHandler(enableSubMenus) ); > > int mnuCount=this.mnuHidden.MenuItems.Count; > > > if(mnuCount > 0) > > { > > this.mnuHidden.MenuItems.Add(this.mnuHidden.MenuItems.Count,mnuit); > > htable.Add(mnuCount, this.TableStyles[stylename].GridColumnStyles[intSelectedCol].Width); > > } > > else > > { > > this.mnuHidden.MenuItems.Add(0,mnuit); > > htable.Add(mnuCount, this.TableStyles[stylename].GridColumnStyles[intSelectedCol].Width); > > } > > > dtStyle.GridColumnStyles[intSelectedCol].Width = 0; > > > Invalidate(); > > this.TableStyles.Add(dtStyle); > > > } > > catch(Exception ex) > > { > > //Do nothing > > MessageBox.Show(ex.Message); > > } > > } > > > > private void BindDefualtDataMember() > > { > > BindingManagerBase cm = this.BindingContext[this.DataSource,this.DataMember] ; > > DataRowView drv =(DataRowView) cm.Current ; > > DataTable dt = drv.Row.Table ; > > dtView = dt.DefaultView; > > > } > >

Loader.
Up arrow icon