[Closed] Populating Dotnet ComboBoxColumns
Hi,
I’m having a bit of difficulty populating comboBoxColumn cells. My usual method populating a dataGridView using row.add doesn’t seem to work and the items property of the cell appears to be read only. Would anyone be able to throw any light this please?
The code below builds a dataGridView with a comboBoxColumn. I want the first column to be a dropdown list.
(
clearListener()
fn defMaxForm =
(
local mf = dotNetObject "MaxCustomCOntrols.MaxForm"
mf.text = "ComboBox Test"
mf.size = dotnetobject "System.Drawing.Size" 500 200
mf
)
fn defDGV =
(
local dg = dotNetObject "System.Windows.Forms.DataGridView"
dg.Location = dotNetObject "Drawing.Point" 0 0
dg.RowsDefaultCellStyle.BackColor = dg.RowsDefaultCellStyle.BackColor.fromARGB 60 60 60
dg.Visible = true
dg.Dock = dg.Dock.Fill
dg.AutoSize = on
dg.SelectionMode = dg.SelectionMode.CellSelect
dg.AutoSizeRowsMode = dg.AutoSizeRowsMode.AllCells
dg.RowHeadersWidthSizeMode = dg.RowHeadersWidthSizeMode.EnableResizing
dg.RowHeadersVisible = false
dg
)
fn fvColumn cn =
(
local col = dotNetObject "DataGridViewTextBoxColumn"
col.headerText = cn
col.readOnly = false
col.resizable = col.resizable.false
col.width = 60
col.ValueType = single
col.DefaultCellStyle.Alignment = col.DefaultCellStyle.Alignment.MiddleRight
col
)
fn comboBoxColumn cn =
(
local col = dotNetObject "DataGridViewComboBoxColumn"
col.headerText = cn
col.readOnly = false
col.minimumWidth = 175
col.AutoSizeMode = col.AutoSizeMode.fill
col.DefaultCellStyle.Alignment = col.DefaultCellStyle.Alignment.MiddleLeft
col.DisplayStyle = col.DisplayStyle.ComboBox
col.FlatStyle = col.FlatStyle.flat
col
)
fn addColumns dgv =
(
dgv.columns.add (comboBoxColumn "Col 1")
dgv.columns.add (fvColumn "Col 2")
dgv.columns.add (fvColumn "Col 3")
)
local myForm = defMaxForm()
local myDGV = defDGV()
addColumns myDGV
for r = 1 to 5 do
(
myDGV.rows.add (#("Cheese Burger", 100, 200))
)
myForm.controls.add myDGV
myForm.showModeless()
print myDGV.rows.item[0].cells.item[0].value
myDGV.rows.item[0].cells.item[0].items = #("Cheese Burger", "Hamburger", "Hotdog")
--#("Cheese Burger", "Hamburger", "Hotdog")
)
Any help would be very appreciated!
fn onEditingControlShowing s e =
(
if (e.Control.GetType()).name == "DataGridViewComboBoxEditingControl" do
(
if (e.Control.DropDownStyle != e.Control.DropDownStyle.DropDown) do
(
e.Control.DropDownStyle = e.Control.DropDownStyle.DropDown
)
)
)
dotnet.addEventHandler dg "EditingControlShowing" onEditingControlShowing
this is the key
Hi Denis,
Thanks for the tip but doesn’t this show me how to edit once the comboBox is populated? I will certainly need this once I get the basic dgv working.
At the moment I just want to populate the comboBoxColumn cell as the dgv is displayed with strings in a mxs array.
Dan
myDGV.rows.item[0].cells.item[0].items.AddRange #("Cheese Burger", "Hamburger", "Hotdog")
Thanks that works.
I’m sure I tried every combination of addRange before…