在绑定列表框中显示两个或更多显示成员(Display two or more displaymembers in binded listbox)

编程入门 行业动态 更新时间:2024-10-23 03:20:46
绑定列表框中显示两个或更多显示成员(Display two or more displaymembers in binded listbox)

连接两个表后,我想显示用户的名称和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";

更多推荐

本文发布于:2023-08-07 05:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460746.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   框中   成员   两个   更多

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!