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.
Unfortunately, activation email could not send to your email. Please try again.

Resize datagrid problem in Winforms

Thread ID:

Created:

Updated:

Platform:

Replies:

3044 Feb 27,2003 12:33 AM Feb 17,2004 11:59 AM Windows Forms 1
loading
Tags: FAQ
VIshnu
Asked On February 27, 2003 12:33 AM

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; }

André
Replied On February 17, 2004 11:59 AM

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; > > > } > >

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;