private string GetPossibleLocationFromSelection() { string location = String.Empty; MissingFolderRow mfr = (MissingFolderRow)this.selectedRowValues[0].Item; // return (mfr == null || mfr.PossibleNewLocation.Count == 0) ? String.Empty : mfr.PossibleNewLocation[0]; int rowIndex = 0; ComboBox comboBox; foreach (MissingFolderRow row in this.observableCollection) { if (row == mfr) { // We foound the row, DataGridRow dataGridRow = (DataGridRow)this.DataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex); if (null == dataGridRow) { break; } comboBox = Util.VisualChildren.GetVisualChild <ComboBox>(dataGridRow, "Part_Combo"); if (null == comboBox) { break; } location = (string)comboBox.SelectedItem; break; } rowIndex++; } return(String.IsNullOrEmpty(location) ? String.Empty : location); }
private IList <DataGridCellInfo> selectedRowValues; // Will contain the tuple of the row corresponding to the selected cell #endregion #region Constructor, Loaded public MissingFoldersLocateAllFolders(Window owner, string rootPath, Dictionary <string, List <string> > missingFoldersAndLikelyLocations) { InitializeComponent(); if (missingFoldersAndLikelyLocations == null || missingFoldersAndLikelyLocations.Count == 0) { // Nothing to do. Abort this.DialogResult = false; return; } this.Owner = owner; this.RootPath = rootPath; this.observableCollection = new ObservableCollection <MissingFolderRow>(); this.EnsureCheckboxValue(); foreach (KeyValuePair <string, List <string> > pair in missingFoldersAndLikelyLocations) { List <string> possibleNewLocations = missingFoldersAndLikelyLocations[pair.Key]; if (possibleNewLocations.Count == 0) { possibleNewLocations.Add(this.useLocateButtonText); } MissingFolderRow row = new MissingFolderRow(Path.GetFileName(pair.Key), pair.Key, possibleNewLocations, false); this.observableCollection.Add(row); } this.DataGrid.ItemsSource = this.observableCollection; }
//private void SetCheckboxValue(CheckBox checkBox) //{ // int rowIndex = 0; // ComboBox comboBox; // foreach (MissingFolderRow mfr in this.observableCollection) // { // DataGridRow dataGridRow = (DataGridRow)this.DataGrid.ItemContainerGenerator // .ContainerFromIndex(rowIndex); // if (Util.VisualChildren.GetVisualChild<CheckBox>(dataGridRow, "Part_Checkbox") == checkBox) // { // comboBox = Util.VisualChildren.GetVisualChild<ComboBox>(dataGridRow, "Part_Combo"); // if (String.IsNullOrEmpty((string)comboBox.SelectedItem)) // { // checkBox.IsChecked = false; // } // } // rowIndex++; // } //} #endregion #region Helper methods private string GetFolderNameFromSelection() { MissingFolderRow mfr = (MissingFolderRow)this.selectedRowValues[0].Item; return((mfr == null) ? String.Empty : mfr.FolderName); }