Hashtable 用法, 用于设置 datagridview headText



对于 不同的表.但有相同的字段.名称也必须相同,那么可以用 hashtable 做到.



  public class tbHashHeadText
   {
      public Hashtable getHashHeadText()
      {
         Hashtable tbHtTxt = new Hashtable();
         tbHtTxt.Add("ImpId", "导入ID");

         tbHtTxt.Add("RptID", "报表ID");
         tbHtTxt.Add("RptCode", "报表代码");
         tbHtTxt.Add("RptName", "报表名");
         tbHtTxt.Add("RptDate", "报表日期");
         tbHtTxt.Add("RptStatus", "报表状态");
         tbHtTxt.Add("CreateDtim", "创建时间");
         tbHtTxt.Add("CreateUser", "创建用户");
         tbHtTxt.Add("CreateIP", "创建IP");
         tbHtTxt.Add("ChangeDtim", "改变时间");
         tbHtTxt.Add("ChangeUser", "改变用户");
         tbHtTxt.Add("ChangeIP", "改变IP");
         tbHtTxt.Add("Note", "备注");
 

         return tbHtTxt;

      }

   }

//-----------------------------------------------------------------------------------------

用法 :


      private void setHeadText(int iTag)
      {
          
         if (iTag == 4 || iTag ==5 )
         {
            DataClass.tbHashHeadText hashText = new tbHashHeadText();

            Hashtable htTb = hashText.getHashHeadText();

            foreach (DictionaryEntry de in htTb)
            {
               if (dataGridView1.Columns[de.Key.ToString()] != null)
               {
                  dataGridView1.Columns[de.Key.ToString()].HeaderText = de.Value.ToString();
               }
            }
         }
 
      }



你可能感兴趣的:(Hashtable 用法, 用于设置 datagridview headText)