获取LINQ中的组合框选定值 [英] Get the Combo Box Selected Value in LINQ

查看:58
本文介绍了获取LINQ中的组合框选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码行从绑定到数据集的组合框中选择一个值.

I have the following lines of code to select a value from a Combo Box bound to a datset.

 

 

DataGridCell 单元格= editingEventArgs.Source as DataGridCell ;

DataGridCell cell = editingEventArgs.Source as DataGridCell;

 

 

如果 (单元格!= )

if (cell != null)

{

 

 

//用于类型化数据集

 

 

对象 obj =((( DataRowView )editingElement.DataContext).行[ .SelectedValuePath];

object obj = ((DataRowView)editingElement.DataContext).Row[this.SelectedValuePath];

当前我有以下行,但是我需要使用C#和LINQ作为泛型来重写此行,我可以将其与多个表一起使用.

Currently i have the following line but i need to rewrite this line using C# and LINQ as a Generic which i can use with multiple tables.

 

 

int vendorAddrID =((( tblVendor_ContactPerson )editingElement.DataContext).contact_addressID;

int vendorAddrID = ((tblVendor_ContactPerson)editingElement.DataContext).contact_addressID;

推荐答案

拥有数据集后,您可以实现IEnumarable并使用linq将其转换为对象

When you have the dataset you can implement the IEnumarable to convert into an object using linq

 

你在这里..

------------------

---------------

 

List< DataRow> xDR =新列表< DataRow>(ds.Tables [0] .AsEnumerable());

List<DataRow> xDR = new List<DataRow>(ds.Tables[0].AsEnumerable());

 

                   < IList< Obj>转换= xDR

                    IList<Obj> converted = xDR

                         ;.选择< DataRow,obj>(

                        .Select<DataRow, obj>(

                             param =>新对象

                            param => new obj

                             {

                            {

                                 Id = Convert.ToInt32(param.ItemArray [0]),

                                Id = Convert.ToInt32(param.ItemArray[0]),

                                 name = param.ItemArray [7],

                                name = param.ItemArray[7],

 

                            }).ToList< obj>();

                            }).ToList<obj>();

希望您的问题得到解决.

Hope your Problem Reolved.

如果需要更多帮助,请告诉我.

Please let me know if you need Any more help.


这篇关于获取LINQ中的组合框选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆