tbh I think i have done something I shouldnt have done as Im a noob and it
appears to work.
1) I dropped a binding source on my form, then dropped a bindingnavigator
and linked the two together in the property editor.
private System.Windows.Forms.BindingSource _dataSource;
private System.Windows.Forms.BindingNavigator Navigator;
2) I created my StringResource class
internal class StringResource
{
private string _stringID = "";
private string _englishOriginal = "";
private string _translation = "";
public string StringID
{
get { return _stringID; }
set { _stringID = value; }
}
public string EnglishOriginal
{
get {return _englishOriginal;}
set{_englishOriginal = value;}
}
public string Translation
{
get { return _translation; }
set { _translation = value; }
}
}
3) I dropped a datagridview on the form and manually created 3 columns. I
then typed in DataPropertyName to link those to the associated properties of
the StringResource class.The following text is what vis studio autogenerated
for my "StringID" datagridview column. I set datagridview.DataSource
property in the designer to my BindingSource
this.ResourceID.DataPropertyName = "StringID";
this.ResourceID.HeaderText = "Resource ID";
this.ResourceID.Name = "ResourceID";
this.ResourceID.ReadOnly = true;
this.ResourceID.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
4) At run time I added new StringResource objects to the BindingSource as
follows
_dataSource.Clear();
foreach(blah blah)
{
StringResource res = new StringResource((string)de.Key, (string)de.Value);
_dataSource.Add(res);
}
So.... _dataSource.DataSource is (none)
Ive not generated any other objects eg DataView, DataTable etc etc
Marc Gravell - 06 Mar 2008 14:17 GMT
First - thankyou for the clear question; you posted enough to reproduce the
issue, without posting the entire app - much appreciated.
Using your code, I added my AdvancedList<T> from here:
http://groups.google.co.uk/group/microsoft.public.dotnet.languages.csharp/msg/2b
7528c689f9ef84
This simply inherits from BindingList<T> and provides sort capabilities.
To attach it, to your grid all you need is something like:
AdvancedList<StringResource> list = new
AdvancedList<StringResource>();
bindingSource1.DataSource = list;
Having done that, I can now sort my DataGridView using the column headers.
Let me know if that works?
Marc
Claire - 07 Mar 2008 15:51 GMT
thank you marc :)
> First - thankyou for the clear question; you posted enough to reproduce
> the issue, without posting the entire app - much appreciated.
Marc Gravell - 07 Mar 2008 15:59 GMT
You're welcome; I hope it worked!
Marc