Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
AnswerRe: Automating the double click required to resize a datagrids columns Pin
ElSpinos14-Sep-07 1:14
ElSpinos14-Sep-07 1:14 
Hey Keith,

There is a private method in the DataGrid control class that you can’t access directly through coding, however, all is not lost as Reflection can assist you here. I’ve done this before and implemented however I can’t find the souce I used so here is a brain dump from what I can remember:

<code>
 // You'd probably want to do this every time the data grid changes it's data
 // so implement the DataSourceChanged event...
 private void MyDataGrid_DataSourceChanged(object sender, System.EventArgs e)
 {
  try
  {
   // First lets get the assembly's type reference...
   Type assemblyType = MyDataGrid.GetType();
   // The DataGrid has a method called ColAutoResize (declared as private and no-one knows why)
   // We can invoke this by getting a reference to it in the MethodInfo class.
   MethodInfo methodInfo = assemblyType.GetMethod("ColAutoResize", BindingFlags.NonPublic);

   // Iterate through your columns...
   for (int i = MyDataGrid.FirstVisibleColumn; (i < MyDataGrid.VisibleColumnCount); i++)
   {
    // Invoke the ColAutoResize method, the method expects a single integer
    // column index as the parameter, so we’ll pass I as an argument in the
    // object[] array.
    methodInfo.Invoke(MyDataGrid, new object[] { i });
   }
  }
  catch (Exception ex)
  {
   // Something went horribly wrong, examine the exception and deal 
   // with it accordingly or just simply ignore it, this shouldn’t 
   // happen anyhow...
  }
 }
</code>


I hope this gets you furthur in your project, happy reflectioning! Smile | :)


Fernando Mendes
Senior .NET Developer, Architect

AnswerRe: Automating the double click required to resize a datagrids columns Pin
AETaylor14-Sep-07 1:18
AETaylor14-Sep-07 1:18 
GeneralRe: Automating the double click required to resize a datagrids columns Pin
ElSpinos14-Sep-07 1:42
ElSpinos14-Sep-07 1:42 
QuestionValidation Error when Schema with Entities [modified] Pin
xfun55614-Sep-07 0:24
xfun55614-Sep-07 0:24 
Questionabut dialog Pin
jason_mf13-Sep-07 23:26
jason_mf13-Sep-07 23:26 
AnswerRe: abut dialog Pin
Dave Kreskowiak14-Sep-07 6:29
mveDave Kreskowiak14-Sep-07 6:29 
QuestionHow to find the number of current window handles for a/my process. [modified] Pin
Martin#13-Sep-07 23:06
Martin#13-Sep-07 23:06 
AnswerRe: How to find the number of current window handles for a/my process. Pin
mav.northwind14-Sep-07 4:07
mav.northwind14-Sep-07 4:07 
GeneralRe: How to find the number of current window handles for a/my process. Pin
Martin#14-Sep-07 7:42
Martin#14-Sep-07 7:42 
GeneralRe: How to find the number of current window handles for a/my process. Pin
Martin#18-Sep-07 21:30
Martin#18-Sep-07 21:30 
QuestionRuntime Web Service Invocation Pin
MrEyes13-Sep-07 22:49
MrEyes13-Sep-07 22:49 
AnswerRe: Runtime Web Service Invocation Pin
ElSpinos14-Sep-07 0:15
ElSpinos14-Sep-07 0:15 
GeneralRe: Runtime Web Service Invocation Pin
MrEyes14-Sep-07 1:04
MrEyes14-Sep-07 1:04 
QuestionDatabase and SQL Pin
halalalal13-Sep-07 22:22
halalalal13-Sep-07 22:22 
AnswerRe: Database and SQL Pin
\laddie13-Sep-07 22:25
\laddie13-Sep-07 22:25 
QuestionSmart Phone Devices Pin
halalalal13-Sep-07 21:57
halalalal13-Sep-07 21:57 
AnswerRe: Smart Phone Devices Pin
Dave Kreskowiak14-Sep-07 6:27
mveDave Kreskowiak14-Sep-07 6:27 
Questionhow to display data in list view of mdi children form on search criteria Pin
mukesh choudhary13-Sep-07 21:52
mukesh choudhary13-Sep-07 21:52 
QuestionCreateDataReader from DataSet in Visual Studio 2003 Pin
Diego F.13-Sep-07 21:43
Diego F.13-Sep-07 21:43 
AnswerRe: CreateDataReader from DataSet in Visual Studio 2003 Pin
Pete O'Hanlon13-Sep-07 21:54
mvePete O'Hanlon13-Sep-07 21:54 
AnswerRe: CreateDataReader from DataSet in Visual Studio 2003 Pin
Colin Angus Mackay13-Sep-07 21:56
Colin Angus Mackay13-Sep-07 21:56 
QuestionCaller ID Pin
p_iranmehr13-Sep-07 21:24
p_iranmehr13-Sep-07 21:24 
AnswerRe: Caller ID Pin
J a a n s13-Sep-07 21:34
professionalJ a a n s13-Sep-07 21:34 
QuestionSend a message to a control Pin
vikas maan13-Sep-07 21:12
vikas maan13-Sep-07 21:12 
AnswerRe: Send a message to a control Pin
\laddie13-Sep-07 21:28
\laddie13-Sep-07 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.