Question

I want to set returning value of a function as data of one of my Datagridview column in C#. for example :

    public class MyMath
    {

        public int X { get; set; }
        public int Y { get; set; }


    }

    public class MyMathOperations
    {
        public int Add(int x, int y)
        {
            return x + y;
        }
    }

    public class MyForm : Form
    {
        List<MyMath> listToShow = new List<MyMath>();
        public MyForm()
        {
            InitializeComponent();
            dataGridView1.DataSource = listToShow;
        }

    }

I want to show listToShow in my Datagridview and i need 3 columns. first column displaying the value of X, Second column displaying the value of Y and the third column displaying returning value of a function that takes X and Y as input parameters(In this example displaying returning value of add function from MyMathOperations that get X and Y as input).

I'm using .Net Framework 4 and Entity Framework 5 and WCF Services. Thanks

Était-ce utile?

La solution

I figured out a solution but what i exactly looking for. Since i am using Entity Framework 5, It generates a partial class for each database table. for above example, MyMath class will look like :

public partial class MyMath
{

    public int X { get; set; }
    public int Y { get; set; }

}

Since my math is a partial class, I added another Class and added this codes :

public partial class MyMath
{
    public int AddXAndY
    {
        get { this.X + this.Y }
        set { }
    }           
}

And i set DatapropertyName of column to "AddXAndY". And I's done. just not in the way i wanted.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top