private void FrmAddEditRoot_Load(object sender, EventArgs e) { ConfigureStyle(); reciever = new RootReciever(); var sources = reciever.GetSources(); // Fill Combo box Helpers.DataHelper helper = new Helpers.DataHelper(); var sourceList = sources.Select(x => new DropDown() { Name = x.SourceName, Value = x.SourceId.ToString() }).ToList(); sourceList.Insert(0, new DropDown() { Name = "-- Select --", Value = (0).ToString() }); helper.FillCombo(cmbSource, sourceList); if (_model != null) { var destinationList = GetDestinationList(_model.Source.ToString()); helper.FillCombo(cmbDestination, destinationList); txtRoot.Text = string.Format("{0} To {1}", _model.DestinationName, _model.SourceName); cmbSource.SelectedIndex = sourceList.Select((obj, index) => new { obj, index }).Where(x => x.obj.Value == _model.Source.ToString()).Select(x => x.index).FirstOrDefault(); cmbDestination.SelectedIndex = destinationList.Select((obj, index) => new { obj, index }).Where(x => x.obj.Value == _model.DestinationId.ToString()).Select(x => x.index).FirstOrDefault(); toggleActive.Checked = _model.IsCheck; } else { _model = new RootModel(); cmbSource.SelectedIndex = 0; cmbDestination.SelectedIndex = 0; } }
private IEnumerable <DropDown> GetDestinationList(string source = null) { var destination = reciever.GetSources().Where(x => x.SourceId.ToString() != source); var destinationList = destination.Select(x => new DropDown() { Name = x.SourceName, Value = x.SourceId.ToString() }).ToList(); destinationList.Insert(0, new DropDown() { Name = "-- Select --", Value = (0).ToString() }); return(destinationList); }