简体   繁体   中英

Assign Tooltip to cell of selected row in Infragistics WebDataGrid

I have an Infragistics WebDataGrid of group names. I would like to add a tooltip to the group cell that lists the doctors associated with this group when the user selects it. I created a row selected event that gets the doctor's names when the group row is selected. The method is below and returns the names when the row is selected. When I assign the string to the tooltip, the tooltip does not show when you mouse over the cell.

protected void wdgMedGrp_RowSelected(object sender, Infragistics.Web.UI.GridControls.SelectedRowEventArgs e)
        {
            Infragistics.Web.UI.GridControls.SelectedRowCollection selectedRows = e.CurrentSelectedRows;
            int iMedicalGroupID = Convert.ToInt32(selectedRows[0].Items.FindItemByKey("ID").Value.ToString());

            //Get Doctor names for this group
            DataTable dtDoctors = new DataTable("Doctors");

            SqlConnection SqlConn = null;
            string strSqlConnection = ConfigurationManager.ConnectionStrings["CAP06"].ConnectionString;
            using (SqlConn = new SqlConnection(strSqlConnection))
            {
                using (SqlCommand SqlCmd = new SqlCommand("phyadmGetPhysicianNames", SqlConn))
                {
                    SqlCmd.CommandType = CommandType.StoredProcedure;
                    SqlCmd.Parameters.Add("@MedicalGroupID", SqlDbType.Int).Value = iMedicalGroupID;
                    SqlConn.Open();
                    using (SqlDataAdapter dataReturned = new SqlDataAdapter(SqlCmd))
                    {
                        dataReturned.Fill(dtDoctors);
                    }
                }
            }

            string strPhysicianNames = string.Empty;
            foreach(DataRow row in dtDoctors.Rows)
            {
               strPhysicianNames += row["PhysicianFullName"].ToString() + "\r\n";
            }

            selectedRows[0].Items.FindItemByKey("Name").Tooltip = strPhysicianNames;
        }

This is my markup:

<ig:WebHierarchicalDataGrid runat="server" height="600px" width="875px" 
AutoGenerateBands="False" AutoGenerateColumns="False" DataKeyFields="ID"
DataMember="SqlDataSource3_DefaultView" StyleSetName="Windows7" ID="wdgMedGrp"
DataSourceID="WebHierarchicalDataSource2" Key="SqlDataSource3_DefaultView" 
OnRowAdded="wdgMedGrp_RowAdded" OnRowSelectionChanged="wdgMedGrp_RowSelected">
<Columns>
    <ig:BoundDataField DataFieldName="ID" Key="ID" Hidden="true">
        <Header Text="ID" />
        <header text="ID" />
    </ig:BoundDataField>
    <ig:BoundDataField DataFieldName="Name" Key="Name" Width="68%">
        <Header Text="Name" />
        <header text="Name" />
    </ig:BoundDataField>
    <ig:BoundDataField DataFieldName="IsVisible" Key="IsVisible" Width="22%">
        <Header Text="Is Visible?" />
        <header text="Is Visible?" />
    </ig:BoundDataField>
</Columns>
 <Behaviors>
    <ig:Filtering>
    </ig:Filtering>
    <ig:RowSelectors EnableInheritance="True" RowSelectorCssClass="groupRowSelectorWidth">
    </ig:RowSelectors>   
    <ig:Selection RowSelectType="Single" Enabled="true" CellClickAction="Row">
        <AutoPostBackFlags RowSelectionChanged="true" />
    </ig:Selection>     
 </Behaviors>   

Why will the tooltip not display?

Thanks.

I had a somewhat similar need. I solved it by creating another hidden column containing the tooltip I wanted for each row, and then set the tooltip in the InitializeRow event, something like this:

Protected void wdgMedGrp_InitializeRow(object sender, RowEventArgs e)
{
    try
    {
       e.Row.Items[1].Tooltip = e.Row.Items[2].Value.ToString();
    }
    catch (Exception){} // ignore any exceptions
}

It worked great. The down side is that I had to do it for each record, one at a time, which meant I could not use the .Fill() method from the SQL call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM