Last edited Jul 20, 2010 at 1:22 AM by ryan_au, version 3

Comments

Abbas_Zolfaghari May 30, 2012 at 4:16 AM 
Fix for GUID Columns
Thanks Dear rtan_aus
My Project Tables contain GUID as Primary key.
So 'DataGridViewAutoFilterExtended' doesn't work fine.
I changed the project to working correctly!

I Get Latest Version from : http://dgvautofilter.codeplex.com/

and Change 2 method in file "DataGridViewAutoFilterComboBoxColumn.cs" as bellow:

public object GetDisplayValue(ICustomTypeDescriptor ictd, object value)
{
if (this.DataSource != null)
{
object holdValue, holdDisplay;
if (!string.IsNullOrEmpty(this.DisplayMember))
{
foreach (object o in this.Items)
{
ICustomTypeDescriptor ic = o as ICustomTypeDescriptor;
holdValue = ic.GetProperties().Find((string.IsNullOrEmpty(this.ValueMember) ? this.DisplayMember : this.ValueMember), true).GetValue(ic);
holdDisplay = ic.GetProperties().Find((string.IsNullOrEmpty(this.DisplayMember) ? this.ValueMember : this.DisplayMember), true).GetValue(ic);
if (holdValue.Equals(value))
{
return holdDisplay;
}
}
}
}

// Return value if we didn't find a match.
return value;
}

public string GetNewFilterValue(string selectedFilterValue, string columnProperty)
{
if (this.DataSource != null)
{
object holdValue, holdDisplay;
if (!string.IsNullOrEmpty(this.DisplayMember))
{
foreach (object o in this.Items)
{
ICustomTypeDescriptor ictd = o as ICustomTypeDescriptor;
holdValue = ictd.GetProperties().Find((string.IsNullOrEmpty(this.ValueMember) ? this.DisplayMember : this.ValueMember), true).GetValue(ictd);
holdDisplay = ictd.GetProperties().Find((string.IsNullOrEmpty(this.DisplayMember) ? this.ValueMember : this.DisplayMember), true).GetValue(ictd);
if (holdDisplay.Equals(selectedFilterValue))
{
if (holdValue is string || holdValue is System.Guid)
{
holdValue = holdValue.ToString();
return string.Format(
"[{0}]='{1}'",
columnProperty,
((string)holdValue).Replace("'", "''"));
}
else
{
return string.Format(
"[{0}]={1}",
columnProperty,
holdValue.ToString());
}
}
}
}
}
else
{
foreach (object o in this.Items)
{
if (o.Equals(selectedFilterValue))
{
if (o is string)
{
return string.Format(
"[{0}]='{1}'",
columnProperty,
((string)o).Replace("'", "''"));
}
else
{
return string.Format(
"[{0}]={1}",
columnProperty,
o.ToString());
}
}
}
}

// Return the currently selected filter value if we didn't find a match.
return selectedFilterValue;
}