00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections.Generic;
00014 using System.Windows.Forms;
00015
00016 namespace Mcs.Epm.MicrosoftProject.mpFx.WinForms
00017 {
00018
00019
00020
00021 public partial class ItemSelectionDialog : Form
00022 {
00023 #region Private Constants
00024
00025 private const int ITEM_CHECKED_COLUMN_INDEX = 0;
00026 private const int ITEM_GUID_COLUMN_INDEX = 2;
00027 private const int ITEM_VALUE_COLUMN_INDEX = 1;
00028
00029 #endregion
00030
00031 #region Instance Data
00032
00033 private readonly Dictionary<Guid, string> _Items;
00034 private readonly bool _AllowMultiSelect;
00035 private Guid _SelectedItem;
00036
00037 #endregion
00038
00039 #region Public Properties
00040
00041 public Dictionary<Guid, string> SelectedItems
00042 {
00043 get
00044 {
00045 Dictionary<Guid, string> selectedItems = new Dictionary<Guid, string>();
00046
00047 foreach (DataGridViewRow row in dataGridView.Rows)
00048 {
00049 if (Convert.ToBoolean(row.Cells[ITEM_CHECKED_COLUMN_INDEX].Value))
00050 {
00051 selectedItems.Add(new Guid(row.Cells[ITEM_GUID_COLUMN_INDEX].Value.ToString()), row.Cells[ITEM_VALUE_COLUMN_INDEX].Value.ToString());
00052 }
00053 }
00054
00055 return selectedItems;
00056 }
00057 }
00058
00059 public Guid SelectedItem
00060 {
00061 get
00062 {
00063 if (_SelectedItem == Guid.Empty)
00064 {
00065 foreach (DataGridViewRow row in dataGridView.Rows)
00066 {
00067 if (Convert.ToBoolean(row.Cells[ITEM_CHECKED_COLUMN_INDEX].Value))
00068 {
00069 _SelectedItem = new Guid(row.Cells[ITEM_GUID_COLUMN_INDEX].Value.ToString());
00070 break;
00071 }
00072 }
00073 }
00074 return _SelectedItem;
00075 }
00076 }
00077
00078 #endregion
00079
00080 #region Constructors
00081
00082 public ItemSelectionDialog(Dictionary<Guid, string> items, bool allowMultiSelect)
00083 {
00084 InitializeComponent();
00085
00086 _Items = items;
00087 _AllowMultiSelect = allowMultiSelect;
00088
00089 foreach (KeyValuePair<Guid, string> item in _Items)
00090 {
00091 dataGridView.Rows.Add(new object[] {null, item.Value, item.Key});
00092 }
00093 }
00094
00095 #endregion
00096
00097 #region Event Handlers
00098
00099 private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
00100 {
00101 if (!_AllowMultiSelect)
00102 {
00103 foreach (DataGridViewRow row in dataGridView.Rows)
00104 {
00105 if (row.Index != e.RowIndex)
00106 {
00107 row.Cells[ITEM_CHECKED_COLUMN_INDEX].Value = false;
00108 }
00109 }
00110 }
00111 }
00112
00113 #endregion
00114
00115 }
00116 }