Datagridview autosizerowmode problem?

cwyong1

Active member
Joined
May 20, 2007
Messages
35
Programming Experience
Beginner
Hi All
Can someone tell the syntax for "AutoSizeRowMode" pls?

What i typed were this
VB.NET:
dgv1.AutoSizeRowMode.AllCells = true

The error return is
"Constant cannot be the target of an assigments (BC30074)"

VB.NET:
	Private Sub SetupGrid()
	
		' For the second grid, columns are generated manually
		dgv1 = New DataGridView()
		dgv1.Name = "dgv1"
		dgv1.AllowUserToOrderColumns = True
		dgv1.AllowUserToDeleteRows = False
		dgv1.AllowUserToAddRows = False
		' Render alternating rows with a different background color
		dgv1.AlternatingRowsDefaultCellStyle.BackColor = SystemColors.InactiveCaptionText
		dgv1.AutoGenerateColumns = False
		dgv1.DataSource = bsUser
		' Only one selection is supported at a time
		dgv1.MultiSelect = False
		' Configure the grid to use cell selection
		dgv1.SelectionMode = DataGridViewSelectionMode.CellSelect
		' Because this grid will contain unbound columns
		' VirtualMode must be On.
		dgv1.VirtualMode = True
 
First off, youre using DataGridView , not datagrid. Please be specific because there IS a difference

Second, AutoSiteRowsMode is an enumeration of type DataGridViewAutoSizeRowsMode. AllCells is a value within this enum. You assign the property a value from the enum:

dgv1.AutoSizeRowMode = DataGridViewAutoSizeRowsMode.AllCells



You do NOT get the value of the current setting of the enum and try to reference another type and set it to true:

dgv1.AutoSizeRowMode.AllCells = true 'no



For clarity, suppose we had a person class, and there was an Age property of person. What you just effectively did was:

person.Age.25 = true


when you should do:

person.Age = 25


See the diff?
 
Back
Top