The challenge comes when you start realizing certain properties are not exposed during run time. For example, you may want to control the row hieght of respective row in the datagrid.
Frustrated about Datagrid's limitation, you may be looking around for third party controls to replace it. However, just before you do that, you may want to find out some unexposed properties in datagrid (or any other controls, as a matter of fact) via reflection.
Here is a sample of how to expose these properties.
1 Public Sub GetGridProperties(ByVal dg As DataGrid)
2 Dim fieldInfos As System.Reflection.FieldInfo() = _
3 dg.GetType.GetFields(BindingFlags.NonPublic Or _
4 BindingFlags.Static Or BindingFlags.Instance)
5
6 For Each fieldInfo As System.Reflection.FieldInfo In fieldInfos
7 Debug.WriteLine(fieldInfo.Name & "," & fieldInfo.FieldType.ToString)
8 Next
9 End Sub
After you run this code, the following properties are exposed for your perusal.
m_kcxDefaultColWidth System.Int32
m_kfDefaultVScrollVisible System.Boolean
m_kfDefaultHScrollVisible System.Boolean
m_kfDefaultColumnHeadersVisible System.Boolean
m_kfDefaultRowHeadersVisible System.Boolean
v_xyDpi System.Int32
v_cxDefaultWidth System.Int32
v_cyDefaultHeight System.Int32
v_cxyDefaultBorderWidth System.Int32
v_cxyDefaultGridLineWidth System.Int32
v_nDefaultTextInset System.Int32
v_cxyDefaultResizePixel System.Int32
v_cxDefaultRowHdrWidth System.Int32
v_cxAutoGenColWidth System.Int32
v_cxyMinRowColWidth System.Int32
m_renderer System.Windows.Forms.GridRenderer
m_tabstycol System.Windows.Forms.GridTableStylesCollection
m_tabstyActive System.Windows.Forms.DataGridTableStyle
m_objDataSource System.Object
m_cmData System.Windows.Forms.CurrencyManager
m_rlrow System.Collections.ArrayList
m_pdcolData System.ComponentModel.PropertyDescriptorCollection
m_fListHandlerActive System.Boolean
m_irowVisibleFirst System.Int32
m_irowVisibleLast System.Int32
m_crowVisible System.Int32
m_cyRow System.Int32
m_fRowHeadersVis System.Boolean
m_icolVisibleFirst System.Int32
m_icolVisibleLast System.Int32
m_ccolVisible System.Int32
m_cyColumnHeader System.Int32
m_fColHeadersVis System.Boolean
m_fValidColsSet System.Boolean
m_icolValidFirst System.Int32
m_icolValidLast System.Int32
m_curcell System.Windows.Forms.DataGridCurrentCell
m_fColResizeActive System.Boolean
m_fRowResizeActive System.Boolean
m_irowcolResize System.Int32
m_xyResizeCur System.Int32
m_xyResizeLast System.Int32
m_xyResizeMax System.Int32
m_xyResizeMin System.Int32
m_fRowSelectDragActive System.Boolean
m_sbHorz System.Windows.Forms.HScrollBar
m_sbVert System.Windows.Forms.VScrollBar
m_yRenderLast System.Int32
m_xRenderLast System.Int32
CurrentCellChanged System.EventHandler
m_hwn System.IntPtr
m_gch System.Runtime.InteropServices.GCHandle
m_wnt Microsoft.AGL.Forms.WNT
m_thread System.Threading.Thread
m_mnucOwned System.Windows.Forms.ContextMenu
m_mnucFloating System.Windows.Forms.ContextMenu
m_qutaskInvoke System.Collections.Queue
m_dataBindings System.Windows.Forms.ControlBindingsCollection
m_bindingContext System.Windows.Forms.BindingContext
m_fDisposed System.Boolean
m_fCalledDispose System.Boolean
m_fDestroyed System.Boolean
m_fEnabledReal System.Boolean
m_objTag System.Object
m_strName System.String
m_cLayoutSuspend System.Int32
m_fScrollableSav System.Boolean
m_fMousePressed System.Boolean
m_fFocusAttempt System.Boolean
m_fSkipValidation System.Boolean
m_bsRequiredScaling System.Windows.Forms.BoundsSpecified
m_cSuspendValidation System.Int32 You will immediately find some of the properties useful - m_rlrow returns arraylist of all rows in the datagrid. you can continue to expose more in depth properties Using reflection by simply drilling down each property. m_cy is exposed if you get fieldinfo under each row m_rlrow arraylist. m_cy return the row hieght of a particular row.
There are a lot more properties to look for, you just need to browse through them and find the property that is useful to you. If you can't find the properties you need, then you can consider third party controls.
No comments:
Post a Comment