C#, LINQ:
Convert List of Type to another Type
Dieses Beispiel konvertiert eine List<FrameworkElement> in eine List<NumberBox>
um
//convert as numberbox
List<NumberBox>
numberBoxes = elements_in_col_1.ConvertAll(x => (NumberBox)x);
|
/*check Nr
FrameworkElement cell_element =
get_cell_child(rowNr, 0);
if (cell_element == null) return; //if no nr field : error
//*check empty nr*
NumberBox
ctlNr=(NumberBox)cell_element;
string sNr =
ctlNr.Text;//get_cell_value(rowNr, 0);
if(sNr=="")
{
//get elements of grid
var children =
grid_folders.Children.Cast<FrameworkElement>();
//filter elements form column 1
List<FrameworkElement>
elements_in_col_1 = children.Where(item => (Grid.GetColumn(item) == 0
&& Grid.GetRow(item) > 0)).ToList();
//convert as numberbox
List<NumberBox>
numberBoxes = elements_in_col_1.ConvertAll(x => (NumberBox)x);
//find max as integer from
numberBox.text
int maxNr =
numberBoxes.findMax();
//increase
maxNr=maxNr+1;
ctlNr.Text = maxNr.ToString();
}
|