locked
Print data table value in tool tip RRS feed

  • Question

  • private void GetGeneralReason()
          {
            try
            {
              txtReason1.Clear();
              SqlConnection conn = new SqlConnection(MFConnProperty.MFsqlConnString);
              conn.Open();
              SqlCommand cmd = new SqlCommand("select f22,f23,f24,f25,f26 from csvtest where f5 = '" + txtFileLinks.Text + "'");
              cmd.Connection = conn;
              cmd.CommandTimeout = 500;
              cmd.ExecuteNonQuery();
              SqlDataAdapter da = new SqlDataAdapter();
              DataTable table = new DataTable();
              da.SelectCommand = cmd;
              da.Fill(table);
              if (table.Rows.Count > 0)
              {
                for (int o = 0; o <= table.Columns.Count - 1; o++)
                {
    
                  if (table.Rows[0][o] == null)
                  {
                    txtReason1.Text += "";
                  }
                  else
                  {
                    if (o < table.Columns.Count - 1)
                    {
                      txtReason1.Text += table.Rows[0][o].ToString() + ",";  //????????
                    }
                    else
                    {
                      txtReason1.Text += table.Rows[0][o].ToString(); ////???
                    }
                  }
    
                }
    
              }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); }
          }
    

    I want to print datatable values in tooltip of textbox "txtReason1" in such a way that all commas is ommited if there is no NULL value found in Data table column.

     

    Please help??

    Sunday, July 24, 2011 8:08 AM

Answers

  • hi haris

    use this procedure :

     

      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;
       
      }
    


     


    • Proposed as answer by Pooyan Fekrati Sunday, July 24, 2011 9:38 AM
    • Marked as answer by Lie You Monday, August 1, 2011 6:23 AM
    Sunday, July 24, 2011 9:37 AM