none
Set time duration in tooltip RRS feed

  • Question

  • private void CreateTooltipValue(DataTable Datatable, TextBox Textbox)
     {
     string tooltip = string.Empty;
     int columns = Datatable.Columns.Count;
     for (int i = 0; i < columns - 1; i++)
     {
     if (! string.IsNullOrEmpty((Datatable.Rows[0][i].ToString())))
     {
      tooltip = tooltip + Datatable.Rows[0][i] + ",";
     }
    
     }
     string FinalTooltip = tooltip.Remove(tooltip.LastIndexOf(","));
     Textbox.ToolTip = FinalTooltip;
     
     }
    


    The above code sample will show data table values in tooltip. I want the visiblity time for these values is 30sec.

     

    App. Info:  2.0/Windows Forms/C#/sql2008/vs2008

     

    Please assist to get it done.

     

    Thanks

    Hussain.


    Tuesday, August 2, 2011 11:23 AM

Answers

  • You can do it via async delegate. Create a Delegate as below,

    public delegate void ShowToolTipDelegate(DataTable Datatable, TextBox Textbox);

    Now instead of calling CreateToolTipValue function, create the object of above delegate and call BeginInvoke on it- as below

    ShowToolTipDelegate toolTipDisplayer = new ShowToolTipDelegate(CreateTooltipValue);
    toolTipDisplayer.BeginInvoke(table, textbox);

    Then, update your CreateToolTipvalue function to display tool tip every 30 secs. I have updated it as below.

    private void CreateTooltipValue(DataTable Datatable, TextBox Textbox)
    {
      string tooltip = string.Empty;
      int columns = Datatable.Columns.Count;
      int rowCount = 0;
    
      while(rowCount < Datatable.Rows.Count)
      {
       for (int i = 0; i < columns - 1; i++)
        {
         if (! string.IsNullOrEmpty((Datatable.Rows[0][i].ToString())))
         {
           tooltip = tooltip + Datatable.Rows[0][i] + ",";
         }
    
         string FinalTooltip = tooltip.Remove(tooltip.LastIndexOf(","));
         Textbox.ToolTip = FinalTooltip;
    
         Thread.Sleep(30000);
         rowCount++;
        }
      }
    }
    

     Hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!
    Tuesday, August 2, 2011 11:58 AM

All replies

  • You can do it via async delegate. Create a Delegate as below,

    public delegate void ShowToolTipDelegate(DataTable Datatable, TextBox Textbox);

    Now instead of calling CreateToolTipValue function, create the object of above delegate and call BeginInvoke on it- as below

    ShowToolTipDelegate toolTipDisplayer = new ShowToolTipDelegate(CreateTooltipValue);
    toolTipDisplayer.BeginInvoke(table, textbox);

    Then, update your CreateToolTipvalue function to display tool tip every 30 secs. I have updated it as below.

    private void CreateTooltipValue(DataTable Datatable, TextBox Textbox)
    {
      string tooltip = string.Empty;
      int columns = Datatable.Columns.Count;
      int rowCount = 0;
    
      while(rowCount < Datatable.Rows.Count)
      {
       for (int i = 0; i < columns - 1; i++)
        {
         if (! string.IsNullOrEmpty((Datatable.Rows[0][i].ToString())))
         {
           tooltip = tooltip + Datatable.Rows[0][i] + ",";
         }
    
         string FinalTooltip = tooltip.Remove(tooltip.LastIndexOf(","));
         Textbox.ToolTip = FinalTooltip;
    
         Thread.Sleep(30000);
         rowCount++;
        }
      }
    }
    

     Hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!
    Tuesday, August 2, 2011 11:58 AM
  • Is the front end WPF? If so there is a ToolTipService.ShowDuration property. Silverlight has a thrid party Tooltip add on that can also specify a duration.
    Louis
    Tuesday, August 2, 2011 6:04 PM