Datagridview help

B

Bill Angus

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
 
B

Bryan Phillips

Why not just programmatically rearrange and hide columns at run time
after the datatable is bound?
 
C

ClayB

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.
 
B

Bill Angus

Awesome Clay... knew it had to be something like that, but cldn't find the info or figure it out from the docs.

Thanks very much. Have a great day!

Bill Angus, MA
http://www.psychtest.com
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top