Awesome!!!
ComboBox 바인딩 방법 여러가지 본문
/***************************************************************************************/
#region ComboBox item list custom binding Method // SetComboBoxItem()
/********************************************************************************START**/
//[string 이용] 직접 item list 입력
private void SetComboBoxItem(ComboBox combo, params string[] strItem)
{
if(area != null)
{
combo.Items.Clear();
for(int i=0; i<area.Length; i++)
{
combo.Items.Add(strItem[i]);
}
combo.SelectedIndex = 0;
}
}
//[ArraryList 이용] ArraryList로 부터 item list Mapping
private void SetComboBoxItem(ComboBox combo, ArrayList arrListItem)
{
combo.Items.Clear();
foreach(string temp in arrListItem)
{
combo.Items.Add(temp);
}
combo.SelectedIndex = 0;
}
//[ArraryList 이용] ArraryList로 부터 item list Mapping + Custom Top String 추가
private void SetComboBoxItem(ComboBox combo, ArrayList arrListItem, params string[] customTopStrAdd)
{
combo.Items.Clear();
if (customTopStrAdd != null)
{
foreach (string temp in customTopStrAdd)
{
combo.Items.Add(temp);
}
}
foreach(string temp in arrListItem)
{
combo.Items.Add(temp);
}
combo.SelectedIndex = 0;
}
//[DataTable 이용1] DB로부터 데이터를 가져와 item list Mapping
private void SetComboBoxItem(ComboBox combo, DataTable dt, string columnName)
{
if(dt != null)
{
combo.Items.Clear();
combo.DataSource = dt;
combo.DisplayMember = columnName;
combo.ValueMember = columnName;
}
combo.SelectedIndex = 0;
}
//[DataTable 이용2] DB로부터 데이터를 가져와 item list Mapping + Top String 추가
private void SetComboBoxItem(ComboBox combo, DataTable dt, string columnName, params string[] customTopStrAdd)
{
combo.Items.Clear();
if (customTopStrAdd != null)
{
foreach (string temp in customTopStrAdd)
{
combo.Items.Add(temp);
}
}
if(dt != null)
{
for (int i=0; i<dt.Rows.Count; i++)
{
combo.Items.Add(dt.Rows[i][columnName].ToString());
}
}
combo.SelectedIndex = 0;
}
//[Xml이용]
private void SetComboBoxItem(ComboBox combo, XmlDocument xDoc, string xpath)
{
XmlNodeList xNode = xDoc.SelectNodes(xpath);
foreach (XmlNode node in xNode)
{
combo.Items.Add(node.Attributes["id"].Value);
}
combo.SelectedIndex = 0;
}
//[Xml이용2]
private void SetComboBoxItem(ComboBox combo, XmlDocument xDoc, string xpath, params string[] customTopStrAdd)
{
combo.Items.Clear();
if (customTopStrAdd != null)
{
foreach (string temp in customTopStrAdd)
{
combo.Items.Add(temp);
}
}
XmlNodeList xNode = xDoc.SelectNodes(xpath);
foreach (XmlNode node in xNode)
{
combo.Items.Add(node.Attributes["id"].Value);
}
combo.SelectedIndex = 0;
}
/*********************************************************************************END***/
#endregion
/***************************************************************************************/