Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
How to display tooltip for different records?
posted
Hi, I'm using an XML data source to populate my xamdatagrid. However, I have no idea how to get tooltips (which are part of the xml data source) to popup for each record whenever the cursor is hovering above it. Can some one give me a simple example? Or point me in the right direction? Thanks Josh
Parents
No Data
Reply
  • 105
    posted

    Josh,

    There is another way to approach this, don't use any styles and just do it in the code-behind directly.

    Bolow is the sample code:

     private void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e)  // this is a mouse over event handler for XamDataGrid
            {
                DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource, typeof(DataRecordPresenter), true) as DataRecordPresenter;

                if (drp == null) { return; }

                //
                //TODO: show your tool tip, you can use reflection to get your current underlying data record, for example:
                //
                StringBuilder toolTip = new StringBuilder();
                string label = string.Empty;
                //
                // Especially if you are using Linq as your underling data source, then reflection is  
                // the unique way to get the values of kinds of fields.
                Type type = drp.DataRecord.DataItem.GetType(); 
                System.Reflection.PropertyInfo[ pInfos = type.GetProperties();

                foreach (System.Reflection.PropertyInfo pi in pInfos)
                {
                    label = xamDataGrid.FieldLayouts[0].Fields[pi.Name].Label.ToString(); // xamDataGrid is your XamDataGrid control name.
                    toolTip.Append(label);
                    toolTip.Append(": ");
                    toolTip.Append(pi.GetValue(drp.DataRecord.DataItem, null));
                    toolTip.Append(Environment.NewLine);
                }
                drp.ToolTip = toolTip.Length > 0 ? toolTip.ToString() : null;
            }

    Hope this helps.

    Corin

Children