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