Datagridview help

  • Thread starter Thread starter Bill Angus
  • Start date Start date
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
 
Why not just programmatically rearrange and hide columns at run time
after the datatable is bound?
 
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.
 
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.
 
Back
Top