DataGrid Column

I was using the following code (on Paint Event) to AutoSize Columns in my datagrid:

Type t = dgTC.DataSource.GetType();
MethodInfo m = t.GetMethod("ColAutoResize", BindingFlags.Instance | BindingFlags.NonPublic);
for (int i = dgTC.FirstVisibleColumn; (i< dgTC.VisibleColumnCount); i++)
{
m.Invoke(dgTC, new object[]{i});
}

But after adding custom tablestyle and column style I am getting following exception:

System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation.

--> System.InvalidOperationException: The '' DataGridColumnStyle cannot
be used because it is not associated with a Property or Column in the DataSource.

At: System.Windows.Forms.DataGridColumnStyle.CheckValidDataSource(CurrencyManager value)

At: System.Windows.Forms.DataGridColumnStyle.GetColumnValueAtRow
(CurrencyManager source, Int32 rowNum)
at System.Windows.Forms.DataGrid.ColAutoResize(Int32 col)
-- End of inner exception stack trace --

at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean
verifyAccess)

at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean verifyAccess)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at TotalControl.frmDataEntry.AutoSizeDataGrid() in c:\documents and settings\
MyComp\my documents\visual studio
projects\totalcontrol\frmdataentry.cs:line 699

Can someone help me with this? Thanks a lot in advance.
[1989 byte] By [Taurian110] at [2007-11-19 14:33:17]