Fix improper datasource binding refreshes

Switch to a BindingList and use extension methods to have Sort and
AddRange.
This commit is contained in:
2013-12-06 11:07:40 -05:00
parent e59521035a
commit 3831a7c5ce
7 changed files with 38 additions and 31 deletions

View File

@@ -12,6 +12,7 @@ using System.Xml.Serialization;
using System.IO;
using Printing.DataGridViewPrint.Tools;
using System.Reflection;
using System.Collections.ObjectModel;
namespace d20_SRD_Spell_Lists {
public partial class FrmMain : Form {
@@ -102,15 +103,9 @@ namespace d20_SRD_Spell_Lists {
var result = MessageBox.Show(question, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result == System.Windows.Forms.DialogResult.Yes) {
character.addAllClassSpells();
refreshSpellList();
}
}
private void refreshSpellList() {
spellsDataGridView.DataSource = null;
setupSpells();
}
private void updateClassInformation(ComboBox classList) {
string charClass = classList.SelectedItem.ToString();
character.CharacterClass = (Character.SpellCastingClasses)Enum.Parse(typeof(Character.SpellCastingClasses), charClass);
@@ -235,7 +230,6 @@ namespace d20_SRD_Spell_Lists {
txtCharacter.Text = character.Name;
txtSpellCastingAttribute.Text = character.SpellCastingAttribute.ToString();
charClassComboBox.SelectedItem = Character.getSpellcastingClassName(character.CharacterClass);
refreshSpellList();
}
private void btnAdd_Click(object sender, EventArgs e) {
@@ -244,7 +238,6 @@ namespace d20_SRD_Spell_Lists {
if (result == System.Windows.Forms.DialogResult.OK) {
character.Spells.Add(addForm.spell);
character.Spells.Sort(new SpellInequalityComparer());
refreshSpellList();
dirtyCharacter = true;
}
}
@@ -256,7 +249,6 @@ namespace d20_SRD_Spell_Lists {
var result = editForm.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK) {
character.Spells[character.Spells.IndexOf(editItem)] = editForm.spell;
refreshSpellList();
dirtyCharacter = true;
}
} else if (isDeleteButtonCell(e)) {
@@ -266,7 +258,6 @@ namespace d20_SRD_Spell_Lists {
var result = MessageBox.Show(msg, title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == System.Windows.Forms.DialogResult.Yes) {
character.Spells.Remove(deleteItem);
refreshSpellList();
dirtyCharacter = true;
}
}