Datagridview headTextを設定するためのHashtableの使い方
1629 ワード
異なるテーブルについて同じフィールドがあります。名前も同じでなければならないので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();
}
}
}
}
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();
}
}
}
}