diff FrmUnit.cs @ 151:540c8aa6e565

Re #269: Handle multiple stat lines * Start to rebuild UI using DataGridView, as we can get the header height from that and it replaces the original DataGrid
author IBBoard <dev@ibboard.co.uk>
date Thu, 06 May 2010 20:05:43 +0000
parents 0e3837170637
children fcd90498d9a2
line wrap: on
line diff
--- a/FrmUnit.cs	Sun May 02 15:46:24 2010 +0000
+++ b/FrmUnit.cs	Thu May 06 20:05:43 2010 +0000
@@ -27,7 +27,7 @@
 	{
 		private Unit unit;
 		private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>();
-		private Dictionary<string, DataGrid> dataGrids = new Dictionary<string, DataGrid>();
+		private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>();
 		private CommandStack commandStack;
 		private System.Windows.Forms.TextBox tbUnitName;
 		private System.Windows.Forms.NumericUpDown unitSize;
@@ -103,7 +103,7 @@
 
 			for (int i = 0; i < statsCount; i++)
 			{
-				DataGrid statsGrid = GetDataGrid(statsIDs[i]);
+				DataGridView statsGrid = GetDataGridView(statsIDs[i]);
 				DataTable dt = (DataTable)statsGrid.DataSource;
 				DataRow dr = dt.NewRow();
 				dr.ItemArray = stats[i];
@@ -111,84 +111,68 @@
 			}
 		}
 
-		private DataGrid GetDataGrid(string statsID)
+		private DataGridView GetDataGridView(string statsID)
 		{
-			DataGrid grid;
+			DataGridView grid;
 
-			if (dataGrids.ContainsKey(statsID))
+			if (DataGridViews.ContainsKey(statsID))
 			{
-				grid = DictionaryUtils.GetValue(dataGrids, statsID);
+				grid = DictionaryUtils.GetValue(DataGridViews, statsID);
 			}
 			else
 			{
-				grid = CreateDataGrid(statsID);
-				dataGrids[statsID] = grid;
+				grid = CreateDataGridView(statsID);
+				DataGridViews[statsID] = grid;
 			}
 
 			return grid;
 		}
 
-		private DataGrid CreateDataGrid(string statsID)
+		private DataGridView CreateDataGridView(string statsID)
 		{
 			SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID);
 			StatSlot[] sysStatSlots = sysStats.StatSlots;
-			StatSlot[] stats = new StatSlot[sysStatSlots.Length + 1];
-			stats[0] = new StatSlot("Name");
-			sysStatSlots.CopyTo(stats, 1);
-			DataColumn[] dc = new DataColumn[stats.Length];
-			DataGridTableStyle dgStyle = new DataGridTableStyle();
-			dgStyle.RowHeadersVisible = false;
+			StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1];
+			statsWithName[0] = new StatSlot("Name");
+			sysStatSlots.CopyTo(statsWithName, 1);
+			DataColumn[] dc = new DataColumn[statsWithName.Length];
 			DataTable dt = new DataTable();
-			int statsCount = stats.Length;
+			int statsCount = statsWithName.Length;
 
 			for (int i = 0; i < statsCount; i++)
 			{
-				StatSlot stat = stats[i];
+				StatSlot stat = statsWithName[i];
 				string slotName = stat.Name;
 				dc[i] = CreateDataColumn(slotName);
-				dgStyle.GridColumnStyles.Add(CreateColumnStyle(slotName));
 			}
 
-			DataGridColumnStyle nameColStyle = dgStyle.GridColumnStyles[0];
-			nameColStyle.HeaderText = Translation.GetTranslation("UnitName", "Name");
-			nameColStyle.Alignment = HorizontalAlignment.Left;
-			DataGrid statsGrid = CreateDataGrid();
-			nameColStyle.Width = statsGrid.ClientSize.Width - ((stats.Length) * 40) - 4;
+			DataGridView statsGrid = CreateDataGridView();
 
 			dt.Columns.AddRange(dc);
 			statsGrid.DataSource = dt;
-			statsGrid.TableStyles.Add(dgStyle);
+			statsGrid.Columns[0].Name = Translation.GetTranslation("UnitName", "Name");
+			statsGrid.Columns[0].Width = statsGrid.ClientSize.Width - ((sysStatSlots.Length) * 40) - 4;
+
+			for (int i = 0; i < statsCount; i++)
+			{
+				statsGrid.Columns[i].CellTemplate = new StatsDataGridViewCell();
+			}
+			
 			return statsGrid;
 		}
 
 		private static DataColumn CreateDataColumn(string slotName)
 		{
-			DataColumn tempCol = new DataColumn(slotName);
-			tempCol.DataType = typeof(Stat);
+			DataColumn tempCol = new DataColumn(slotName,  typeof(Stat));
 			return tempCol;
 		}
 
-		private static DataGridColumnStyle CreateColumnStyle(string slotName)
+		public DataGridView CreateDataGridView()
 		{
-			DataGridColumnStyle colStyle = new StatColumnStyle();
-			colStyle.Width = 40;
-			colStyle.MappingName = slotName;
-			colStyle.HeaderText = slotName;
-			colStyle.Alignment = HorizontalAlignment.Center;
-			colStyle.ReadOnly = true;
-			return colStyle;
-		}
-
-		public DataGrid CreateDataGrid()
-		{
-			DataGrid statsGrid = new DataGrid();
-			statsGrid.AllowNavigation = false;
-			statsGrid.AllowSorting = false;
+			DataGridView statsGrid = new DataGridView();
 			statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
 						| System.Windows.Forms.AnchorStyles.Right)));
-			statsGrid.CaptionVisible = false;
 			statsGrid.CausesValidation = false;
-			statsGrid.PreferredColumnWidth = 40;
 			statsGrid.ReadOnly = true;
 			statsGrid.RowHeadersVisible = false;
 			statsGrid.Size = new System.Drawing.Size(600, 88);