如何在F#中使用2个Combobox和2个TextBox在Datagridview中添加一行?

时间:2013-09-02 11:24:56

标签: c# winforms datagridview f#

我是F#语言的新手,我必须在gridview中添加一行。

enter image description here

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

1 个答案:

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

    }

}

}

输出

enter image description here