Hello,
I'm having some trouble converting code and logic from VB.NET over to C#. What I'm basically trying to do is combine two columns in an entity table into one for displaying in a datagridview column.
In VB.NET I completed this task with the following code:
Partial Public Class Employee
Public ReadOnly Property GetFullName
Get
Dim FullName As String = FirstName & " " & LastName
Return FullName
End Get
End Property
End Class
In the code above, my partial class "Employee" was actually a direct reference to the Employee table in my Entity Model and FirstName and LastName are both columns in the table. This worked perfectly in VB.NET.
Now I'm working on a separate project in C# and I'm trying to achieve the same results. However, after converting my VB.NET code to C#, I can't find the method when setting the columns "DataPropertyName".
I'm thinking this is because either the code works, but only when I'm manually coding each column and not just filling it with a bindingsource or because the logic in VB.NET is different then C# and C# has a different way of achieving this same result.
Here's the code I tried in C#:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public partial class Employee
{
public object GetFullName {
get {
string FullName = FirstName + " " + LastName;
return FullName;
}
}
}
The above code doesn't throw any errors or anything. But it doesn't do what I'm hoping for either. I've tried several variations like using "static", but nothing seems to work.
So my questions is will anyone help me with the code necessary to accomplish this? Or if its not possible, will anyone help me with understanding the logic that is needed to accomplish this in another way?
And just to clarify what I need help with doing is to set the "DataPropertyName" of a column to the new partial class that will hold the combined information. So after creating the class, I can select it in the drop down menu for the columns data property name.
Also, I'm using Visual Studio 2010 and SQL Server 2008 if it matters.
Thanks for any and all possible help.
UPDATE:
Okay so with the following code, I can actually call my Employee columns, but I still don't get the option to use it as the data property name of a dgv column.
public partial class Employee : NEIInventorySystemDAL.Employee
{
public string GetFullName
{
get
{
return this.FirstName + " " + this.LastName;
}
}
}