To visualize data from the F # interactive console, I can do the following:
open System.Windows.Forms
let testgrid (x) =
let form = new Form(Visible = true)
let data = new DataGridView(Dock = DockStyle.Fill)
form.Controls.Add(data)
data.DataSource <- x
testgrid [|(1,1);(2,2)|]
But if I put the above into a compiled F # program and call testgrid [|(1,1);(2,2)|]
inside the program, I get only a frozen window without data. what needs to be done to make this testgridwork for an F # executable program?
EDIT: with ildjarn answer and some search, is the following code OK? Any pitfalls?
let testgrid x =
let makeForm() =
use form = new Form()
new DataGridView(Dock = DockStyle.Fill, DataSource = x) |> form.Controls.Add
Application.Run form
let thread = new System.Threading.Thread(makeForm)
thread.SetApartmentState(Threading.ApartmentState.STA)
thread.Start()
source
share