Click here to Skip to main content
15,902,275 members
Home / Discussions / C#
   

C#

 
GeneralRe: Class Properties Pin
Nick Parker19-Aug-04 5:55
protectorNick Parker19-Aug-04 5:55 
GeneralEditing the Registry Pin
Stuggo19-Aug-04 0:52
Stuggo19-Aug-04 0:52 
GeneralRe: Editing the Registry Pin
BrcKcc19-Aug-04 4:06
BrcKcc19-Aug-04 4:06 
GeneralRe: Editing the Registry Pin
Salil Khedkar19-Aug-04 20:20
Salil Khedkar19-Aug-04 20:20 
GeneralControl properties Pin
lustuyck18-Aug-04 23:52
lustuyck18-Aug-04 23:52 
GeneralRowFilter Pin
Reinier van de Wetering18-Aug-04 22:56
Reinier van de Wetering18-Aug-04 22:56 
GeneralRe: RowFilter Pin
sreejith ss nair19-Aug-04 19:10
sreejith ss nair19-Aug-04 19:10 
GeneralConvert DataGrid.DataSource to DataTable Pin
kGeniusProject18-Aug-04 22:45
kGeniusProject18-Aug-04 22:45 
Hi,

i've picked up this code (on syncfusion.com) to autosize the heights of a datagrid row.
<br />
		public void AutoSizeGrid(DataGrid gridTasks) <br />
 <br />
		{ <br />
			// DataGrid should be bound to a DataTable for this part to <br />
			// work. <br />
			int numRows = ((DataTable)gridTasks.DataSource).Rows.Count; <br />
			Graphics g = Graphics.FromHwnd(gridTasks.Handle); <br />
			StringFormat sf = new StringFormat(StringFormat.GenericTypographic); <br />
			SizeF size; <br />
<br />
			// Since DataGridRows[] is not exposed directly by the DataGrid <br />
			// we use reflection to hack internally to it.. There is actually <br />
			// a method get_DataGridRows that returns the collection of rows <br />
			// that is what we are doing here, and casting it to a System.Array <br />
			MethodInfo mi = gridTasks.GetType().GetMethod("get_DataGridRows", <br />
				BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance <br />
				| BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); <br />
			System.Array dgra = (System.Array)mi.Invoke(gridTasks,null); <br />
<br />
			// Convert this to an ArrayList, little bit easier to deal with <br />
			// that way, plus we can strip out the newrow row. <br />
			ArrayList DataGridRows = new ArrayList(); <br />
 <br />
			foreach (object dgrr in dgra) <br />
			{ <br />
				if (dgrr.ToString().EndsWith("DataGridRelationshipRow")==true) <br />
					DataGridRows.Add(dgrr); <br />
			} <br />
 <br />
			// Now loop through all the rows in the grid <br />
			for (int i = 0; i < numRows; ++i) <br />
			{ <br />
				// Here we are telling it that the column width is set to <br />
				// 400.. so size will contain the Height it needs to be.<br />
				size = g.MeasureString(gridTasks[i,1].ToString(),gridTasks.Font,400,sf); <br />
				int h = Convert.ToInt32(size.Height);<br />
				// Little extra cellpadding space <br />
				h = h + 8; <br />
				// Now we pick that row out of the DataGridRows[] Array <br />
				// that we have and set it's Height property to what we <br />
				// think it should be. <br />
				PropertyInfo pi = DataGridRows[i].GetType().GetProperty("Height"); <br />
				pi.SetValue(DataGridRows[i],h,null); <br />
				// I have read here that after you set the Height in this manner that you should <br />
				// Call the DataGrid Invalidate() method, but I haven't seen any prob with not calling it.. <br />
			} <br />
			g.Dispose(); <br />
		}<br />


On the line "int numRows = ((DataTable)gridTasks.DataSource).Rows.Count;" I get the error: "Specified Cast is not valid.
I think there's problem with converting the datasource to a datatable??

I'm quite a beginner in programming. So probably it is something easy, but I can't find out what...

Thanks in advance,
Genius

Genius is 1% inspiration and 99% perspiration
Generala Question on DataGrid in WebForm Pin
NickyWang18-Aug-04 21:29
NickyWang18-Aug-04 21:29 
GeneralRe: a Question on DataGrid in WebForm Pin
googou18-Aug-04 22:05
googou18-Aug-04 22:05 
GeneralRe: a Question on DataGrid in WebForm Pin
NickyWang18-Aug-04 22:19
NickyWang18-Aug-04 22:19 
GeneralCustom Control Serialization Pin
Member 1697718-Aug-04 21:25
Member 1697718-Aug-04 21:25 
GeneralDatabase transaction from client - XMLWEBService - COM+ Pin
yu-yu18-Aug-04 21:23
yu-yu18-Aug-04 21:23 
GeneralFacing problem while calling C# Functions(DLL) from Visual Basic(EXE) Pin
Ami Shah18-Aug-04 20:43
Ami Shah18-Aug-04 20:43 
GeneralFacing problem while calling C# Functions(DLL) from Visual Basic(EXE) Pin
Ami Shah18-Aug-04 20:41
Ami Shah18-Aug-04 20:41 
GeneralMaking an application pause Pin
eggie518-Aug-04 18:16
eggie518-Aug-04 18:16 
GeneralRe: Making an application pause Pin
Tom Larsen19-Aug-04 6:52
Tom Larsen19-Aug-04 6:52 
GeneralRe: Making an application pause Pin
eggie519-Aug-04 7:23
eggie519-Aug-04 7:23 
GeneralRe: Making an application pause Pin
Salil Khedkar19-Aug-04 20:34
Salil Khedkar19-Aug-04 20:34 
QuestionObfuscation / Secure source code? Pin
econner18-Aug-04 18:12
econner18-Aug-04 18:12 
AnswerRe: Obfuscation / Secure source code? Pin
Tom Larsen19-Aug-04 7:01
Tom Larsen19-Aug-04 7:01 
GeneralRe: Obfuscation / Secure source code? Pin
econner19-Aug-04 7:15
econner19-Aug-04 7:15 
GeneralRe: Obfuscation / Secure source code? Pin
leppie19-Aug-04 13:05
leppie19-Aug-04 13:05 
GeneralDebugging the .NET application from Remote System. Pin
softp_vc18-Aug-04 18:06
softp_vc18-Aug-04 18:06 
QuestionParameterized constructor? Pin
sachinkalse18-Aug-04 16:40
sachinkalse18-Aug-04 16:40 

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.