我是F#语言的新手,我必须在gridview中添加一行。
这就是我的GridView和代码 C#
public partial class Form1 : Form, IMainView
{
public event EventHandler<ViewEventData> ModelChanged;
private void samplesButton_Click(object sender, EventArgs e)
{}
}
F#
type MainPresenter(view : IMainView) =
let arrayTrackPosition = Array.create 100 ""
let xlApp = new Excel.ApplicationClass()
let xlWorkBookInput = xlApp.Workbooks.Open(@"C:\Projects\Tool\Versuch\VersuchZuEditieren.xlsx")
let viewStateMachine state event =
match state, event with
|{State = _}, SamplesClicked ->
## What come here? ##
{State = "Samples"}
member this.Initialize() = Event.scan viewStateMachine { State = "Consumables" } view.ModelChanged |> ignore
type ViewEventData =
| ConsumablesClicked of BarcodeConsumablesViewModel
| ReagentsClicked of BarcodeReagentsViewModel
| SamplesClicked
答案 0 :(得分:1)
因为我现在不是F#,但在C#中我完成了这件事。 我正在粘贴C#代码..这将让您了解如何在F#中实现,它可以帮助您 UP VOTE 答案
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace grid_example
{
public partial class Form1 : Form
{
DataGridView dgv = new DataGridView();
public Form1()
{
InitializeComponent();
panel1.Controls.Add(dgv);
dgv.Dock = DockStyle.Fill;
dgv.AllowUserToAddRows = false;
//dgv.RowHeadersVisible = false;
define_gridview_columns();
add_rows();
}
public void define_gridview_columns()
{
DataGridViewTextBoxColumn tbox1 = new DataGridViewTextBoxColumn();
tbox1.HeaderText = "Track Postion";
tbox1.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridViewTextBoxColumn tbox2 = new DataGridViewTextBoxColumn();
tbox2.HeaderText = "Tube Sample Content";
tbox2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridViewComboBoxColumn cbox1 = new DataGridViewComboBoxColumn();
cbox1.HeaderText = "Sample Media";
cbox1.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridViewComboBoxColumn cbox2 = new DataGridViewComboBoxColumn(); ;
cbox2.HeaderText = "Sample Test";
cbox2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dgv.Columns.Add(tbox1);
dgv.Columns.Add(tbox2);
dgv.Columns.Add(cbox1);
dgv.Columns.Add(cbox2);
}
public void add_rows()
{
for (int i = 0; i < 10; i++)
{
dgv.Rows.Add();
}
}
}
}
输出