Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding columns in Datagrid - value doesn't fall within expected range 1

Status
Not open for further replies.

robert201

Programmer
Jul 18, 2007
80
TH
Hello,

This is using the Compact Frame 2.0

I have found some code that seems to work. However, the idea of the grid is for the user to keep adding new products to the datagrid. Even though the columns that are needed are added ok. When the user attempts to add a second row there is an error. "Value does not fall within the expected range". This happens each time, after the first one has been successfully added. 2nd one onwards.

I thought it might be the tblStyle object, but as I am creating a new one each time, I am surprised to get this error.

Many thanks,

Steve
Code:
Dim tblStyle As New DataGridTableStyle() 
tblStyle.MappingName = "OrderDetail" 

Dim column As New DataGridTextBoxColumn() 
column.MappingName = "Beverage" 
column.HeaderText = "Beverage" 
tblStyle.GridColumnStyles.Add(column) 

column = New DataGridTextBoxColumn() 
column.MappingName = "BeverageQty" 
column.HeaderText = "Quantity" 
tblStyle.GridColumnStyles.Add(column) 

grdBeverages.TableStyles.Add(tblStyle) 'Error - "Value does not fall within the expected range" 
grdBeverages.DataSource = DS.OrderDetail.DefaultView
 
Well, first I would like to ask why you are rebuilding the TableStyle each time you add a new row. This shouldn't be necessary.

If for some reason it is necessary, you need to clear out the DataGrid's existing TableStyle before you add another:

[red]grdBeverages.TableStyles.Clear()[/red]
grdBeverages.TableStyles.Add(tblStyle)



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top