问题描述
这是我第一次将WPF与LINQ一起使用
我正在编写以下代码来加载列表框
Hi,
This is the first time i am using WPF with LINQ
I am writing the below code to load the listbox
string usageIndicator = AppEnvironment.ToUpper() == "PROD" ? "P" : "T";
using (X12837DataContext dc = new X12837DataContext(_ediConnectionstring))
{
IList<tbl837SubmissionGroupData> submissionGroups = dc.tbl837SubmissionGroupDatas.Where(s => s.UsageIndicator == usageIndicator &&
(s.SelectClaimsByDate == "Y" || s.SelectClaimsNotSent == "Y")).OrderBy(g => g.SubmissionGroupName).ToList();
lstBoxSubmissionGroup.ItemsSource = submissionGroups;
lstBoxSubmissionGroup.DisplayMemberPath = "SubmissionGroupName";
ResponseText = string.Format("{0} submission groups listed.\n", submissionGroups.Count);
}
其中tbl837SubmissionGroupData是包含所有属性的类,
SubmitGroups和submissionGroupName是属性.
现在的数据就像提交组有[0],[1],[2],[3]
哪个内部变量包含变量...
[0] ==> id,groupname,groupid
所以我想检查所有列表[0] [1] [2] [3]来查找一个字符串,假设"mat"是整个列表中的唯一值并获取其索引.
例如我在[2]中找到了mat,然后我想返回2作为索引
怎么做.我在上面的代码之后编写了以下代码,但是现在没有用了,请您提出一种更好的方法或通过任何链接帮助我
where tbl837SubmissionGroupData is a class containing all the attributes ,
submissionGroups andsubmissionGroupName are the attributes.
now the data is like submissiongroups have [0],[1],[2],[3]
which internall contains variables...
[0] ==> id, groupname,groupid
so i want to check all the list [0][1][2][3] data to find a string suppose "mat"which is a unique value in the entire list and get its index.
for example i found mat in [2] then i want to return 2 as index
how to do that. i wrote the following code after the above code but no use i am getting nowher could u please suggest a better approach or help me with any link
IEnumerable items = lstBoxSubmissionGroup.Items;
foreach (object obj in items)
{
string val = obj as string;
if ((!string.IsNullOrEmpty(val)) && val.Contains(searchString))
{
int id = lstBoxSubmissionGroup.Items.IndexOf(obj);
}
}
推荐答案
IEnumerable items = lstBoxSubmissionGroup.Items;
foreach (var item in lstBoxSubmissionGroup.Where(Source => Source.groupName== "XYZ"))
{
//Index in the main collection
Console.WriteLine(submissionGroups.IndexOf(item));
//Index in the Subset
Console.WriteLine(lstBoxSubmissionGroup.IndexOf(item));
}
*如果这解决了您的查询,则标记为答案.
* Mark as answer if this solved your query.
这篇关于在WPF中将搜索字符串与ILIST进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!