Wednesday, July 25, 2012

Show Tooltip on Datagridview of relevant record in c#


 private void dgvItemList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            string newLine = Environment.NewLine;
            string DocNo, Date;
            if (e.ColumnIndex == 1)
            {
                DataGridViewCell cell = dgvItemList.Rows[e.RowIndex].Cells[e.ColumnIndex];
                if (e.Value.Equals("H"))
                {                        
                            string ItemNo = dgvItemList[0, e.RowIndex].Value.ToString();
                            DataTable dtItemNo = App_Code.Class1.TooltipItemList(ItemNo);
                            if (dtItemNo.Rows.Count > 0)
                            {
                                DocNo=dtItemNo.Rows[0]["Invoice No"].ToString();
                                Date = dtItemNo.Rows[0]["Date"].ToString();
                                string Unit = dtItemNo.Rows[0]["Unit Price"].ToString();
                                cell.ToolTipText ="InvoiceNo: "+DocNo+" Date: "+Date+" Price:"+Unit;
                            }    
                        }
                    }
                      
            }

Thursday, July 5, 2012

Open .hta file Application in Windows Form using C#


using System.IO;                 // File.
using System.Diagnostics;        // Process.





 private void button3_Click(object sender, EventArgs e)
 {
    string  sFileHTA = C:\Users\dattatray\Desktop\UPS\RatingToolGenSource\RatingTool.hta";
string sErr = ""; sErr = Open_HTA(sFileHTA); if (sErr != "") { MessageBox.Show(sErr); } } // Open an HTML Application. private string Open_HTA(string sFileName_hta) {  
    string sErr = "";
     if (File.Exists(sFileName_hta) == false)
     {
         return "Application not found.";
     }
     try
     {
         Process p = new Process();
         p.StartInfo.UseShellExecute = true;
         p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
         p.StartInfo.ErrorDialog = true;
         p.StartInfo.FileName = sFileName_hta;
         p.Start();
         p.Dispose();
     }
     catch (Win32Exception ex)
     {
         sErr = ex.Message;
     }
     return sErr;
 }