Help with syntax

K

Ken Foskey

I have an object ScriptWords derived from "Dictionary<String,object>" and
I want to sort words.Keys in simple string order but the whole
orderby<> totally eludes me. Can someone help me. Reading msdn or
searching google is not getting me to a sample I can understand.

I could use SortedDictionary however this form use should be extremely
small (more of a debugging tool) and I am happy to for the screen build
to be slightly slower for general application performance.

See the TODO in the code below.

DictionaryView in the code is defined:
private System.Windows.Forms.DataGridView DictionaryView;


public partial class WordDictionary : Form
{
BindingList<WordValue> Words = new BindingList<WordValue>();

/// <summary>
/// Create new screen that is a simple look at the data available
to scripting
/// </summary>
/// <param name="words"></param>
public WordDictionary( ScriptWords words )
{
InitializeComponent();

// TODO: Sort word dictionary into key order
foreach (String key in words.Keys )
{
WordValue temp = new WordValue();
temp.Key = key;
Object t = words[key];
if (t == null)
temp.Value = "Null - Contact support";
else
temp.Value = words[key].ToString();
Words.Add(temp);
}

DictionaryView.DataSource = Words;
DictionaryView.Columns[0].AutoSizeMode =
DataGridViewAutoSizeColumnMode.AllCells;
DictionaryView.Columns[0].SortMode =
DataGridViewColumnSortMode.Automatic;
DictionaryView.Columns[1].AutoSizeMode =
DataGridViewAutoSizeColumnMode.AllCells;

}
}

Ken
 
K

Ken Foskey

Sorry I missed the simple word object:

class WordValue
{
public String Key { get; set; }
public String Value { get; set; }

public override string ToString()
{
return Value;
}
}


I keep seeing a template for key value pair that I probably should be
using here.
 
K

Ken Foskey

But at the very least, don't have variables that differ only by case.

Thanks for the help, worked perfectly. I tried lots of permutations
close to that, just not that.

I tend to use lower case for constructors input and upper case for the
class variable:

class x
{

private int Game;
public x( int game)
{
Game = game;
}
}

I like the idea that the name does not change. Unfortunately when you
change the whole constructor you should then change the class variable.
In this case I forgot, highlighting a real problem with this style.

Thanks
Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top