连接两个表后,我想显示用户的名称和first_name:
string name_p = list_profiles.Text; int id_profile; var profile = SundicappEntities.Instance.users_profiles.First(u => u.name_p== name_p); id_profile = profile.id_profile; var q = from user in SundicappEntities.Instance.users join map in SundicappEntities.Instance.user_profile_map on user.id_user equals map.id_user where map.id_profile==id_profile select new { user.name_user, user.f_name_user }; usersBindingSource1.DataSource = q.ToList(); listBox_map.DataSource = usersBindingSource1; listBox_map.DisplayMember = "name_user"+" " + "f_name_user";它返回正确的数据,但它显示如下:
{name_user = xxxx.f_name_user = YYYY}
我的问题是如何在列表框中显示许多显示成员! 谢谢你帮帮我。
After joining two tables, i want to display the name and the first_name of user:
string name_p = list_profiles.Text; int id_profile; var profile = SundicappEntities.Instance.users_profiles.First(u => u.name_p== name_p); id_profile = profile.id_profile; var q = from user in SundicappEntities.Instance.users join map in SundicappEntities.Instance.user_profile_map on user.id_user equals map.id_user where map.id_profile==id_profile select new { user.name_user, user.f_name_user }; usersBindingSource1.DataSource = q.ToList(); listBox_map.DataSource = usersBindingSource1; listBox_map.DisplayMember = "name_user"+" " + "f_name_user";It returns the correct data, but it display it like this:
{name_user=xxxx.f_name_user=yyyy}
My problem is how to display many displaymembers in listbox! Thank you to help me.
最满意答案
在类对象中创建一个返回正确字符串的自定义属性。
public string ListBoxItemDisplayText { get { return name_user + " " + f_name_user ; } }您也可以在linq new构造中创建此属性
select new { ListBoxItemDisplayText = user.name_user + " " + user.f_name_user };将此属性绑定到DisplayMember属性。
listBox_map.DisplayMember = "ListBoxItemDisplayText";
Create a custom property in your class object that returns you the correct string.
public string ListBoxItemDisplayText { get { return name_user + " " + f_name_user ; } }You can create this property in the linq new construct as well
select new { ListBoxItemDisplayText = user.name_user + " " + user.f_name_user };Bind this property to the DisplayMember property.
listBox_map.DisplayMember = "ListBoxItemDisplayText";
更多推荐
发布评论