1

我有一些简单的 EF Code-First 类和上下文:

public class Product
{
    public Guid ProductId { get; set; }
    public string Name { get; set; }
    public string ValueType { get; set; }
    public byte[] Value { get; set; }          
}

public class ProductContext : DbContext
{
    public DbSet<Product> Products { get; set; }
}

我有绑定到该上下文的 DataGridView:

private void Form1_Load void (object sender, EventArgs e)
{
    ProductContext _context = new ProductContext();

    // Load data from the database into entities. 
    _context.Categories.Load();

    // Enabling two-way binding between DataGridView and entities
    DataGridView.DataSource = _context.Products.Local.ToBindingList();
}

而且我需要在将其显示到 DataGridView 之前实现Product.Value格式(取决于Product.ValueType)(例如,将Double的byte[]表示形式转换为真正的Double)。但我不知道该怎么做..

P.S. All I've found googling is that I can use Format and Parse events of Binding class (which is after that added to DataBindings property of the control). But as far as I know, Binding class is suitable for simple controls like TextBox, Button, etc.

So I need your help..

Thank you.

4

0 回答 0