1

我是 F# 语言的新手,我必须可以在网格视图中添加一行。

在此处输入图像描述

这就是我的 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
4

1 回答 1

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();
        }

    }

}

}

输出

在此处输入图像描述

于 2013-09-05T12:48:38.667 回答