I have 10 textboxes in my winform.
For performing some validation, I use the OnValidating event handler for doing some processing. For the sake of convenience I have added all these textbox controls in an IEnumerable collection.
IEnumerable<TextBox> txtBoxList;
Inside the OnValidating eventhandler, I need help with LINQ query to get all the current values of the textboxes in the form of string collection
i.e. IList<string> contentList;
Now, my requirement is to get values of the textbox(non-empty) as a string collection. I want to make use of LINQ.
This query I used, is returning me only distinct values
contentList = txtBoxList.GroupBy(t => t.Text)
.Where(g => !string.IsNullOrEmpty(g.Key))
.Select(grp => grp.Key)
.ToList();
i.e., if textbox1 and textbox2 is having the same content,
ex: textbox1 : "John" and textbox2 : "John"
then it returns only one occurrence of "John".
I need your assistance to get all the values of the textbox (including duplicates ) inside string collection
Awaiting response VATSAG
Aucun commentaire:
Enregistrer un commentaire