Groups | Blog | Home
all groups > dotnet windows forms > april 2007 >

dotnet windows forms : Datagridview help



Bill Angus
4/14/2007 2:03:19 PM
I'm looking for help with datagridview. I have a form that works with a
Databale bound to a datagridview. However I only want to display and edit a
few colums (in a different order than they appear in the underlying
datatable).

When I set autogeneratecolumns to false, as in the example below, the
columns show up with no data in them and are not bound to the underlying
datatable. The example below works fine when I allow autogenerate columns.
Howver I get a datagridview which includes all of the columns in the
underlying datatable.

Does anybody know what steps exatly autogeneratecolumns takes, so that I can
replicate them to create the databinding manually? Any help greatly
appreciated.
---------------------------
MyItemTable.Clear()
myItemAdapter.Fill(MyItemTable)
MyItemTable.PrimaryKey = New DataColumn() {MyItemTable.Columns("refnum")}
MyItemTable.Columns("refnum").AllowDBNull = True
dgvInvoiceItems.AutoGenerateColumns = False
dgvInvoiceItems.DataSource = MyItemTable
With (dgvInvoiceItems)
.EditMode = DataGridViewEditMode.EditOnEnter
.Columns.Add("qty", "OrderQty")
.Columns("qty").DefaultCellStyle.Font = New
System.Drawing.Font(Control.DefaultFont, FontStyle.Bold)
.Columns.Add("soldqty", "SoldQty")
.Columns.Add("unitprice", "Price")
.Columns("unitprice").DefaultCellStyle.Format = "c"
end with

Bryan Phillips
4/14/2007 10:23:51 PM
Why not just programmatically rearrange and hide columns at run time
after the datatable is bound?

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net



[quoted text, click to view]
ClayB
4/15/2007 2:46:09 AM
You need to set the DataPropertyName on each column so the
DataGridView knows where to get the values for the column that you are
calling "qty".


..Columns("qty").DataPropertyName = "qty"

================
Clay Burch
Syncfusion, Inc.
Bill Angus
4/15/2007 9:32:20 AM
Awesome Clay... knew it had to be something like that, but cldn't find =
the info or figure it out from the docs.=20

Thanks very much. Have a great day!

Bill Angus, MA
http://www.psychtest.com
[quoted text, click to view]
You need to set the DataPropertyName on each column so the
DataGridView knows where to get the values for the column that you are
calling "qty".


.Columns("qty").DataPropertyName =3D "qty"

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Clay Burch
AddThis Social Bookmark Button