My Name is Kay....

DIY , 먹방 , 개발 , 육아 , 여행 좋아합니다.
AdBlock 사용시 화면이 정상적으로 노출되지 않습니다.
포스팅 관련 문의 및 개발 문의는 Email : wkzkfmxksi@gmail.com

추가 포스팅이 이뤄지지 않는 블로그입니다. 문의는 wkzkfmxksi@gmail.com 으로 연락주세요.
kay
조회 수 16007 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
* Add 1 : 수동 추가 
public class ComboboxItem
{
    public string Text { get; set; }
    public object Value { get; set; }

    public override string ToString()
    {
        return Text;
    }
}
 
private void Test()
{
    ComboboxItem item = new ComboboxItem();
    item.Text = "Item text1";
    item.Value = 12;

    comboBox1.Items.Add(item);

    comboBox1.SelectedIndex = 0;

    MessageBox.Show((comboBox1.SelectedItem as ComboboxItem).Value.ToString());
}



* Add 2 : DataBase 연동

private void frmCityMapping_Load(object sender, EventArgs e) {
  string ConnectionString = "server=아이피;database=데이터베이스;uid=아이디;pwd=패스워드;"; 
  try {
    SqlConnection dbConn = new SqlConnection(ConnectionString);
    dbConn.Open();
    SqlCommand cmd = new SqlCommand("SELECT splyCd,splyEnm FROM tblsupply order by splyEnm", dbConn);
     
    using(var myReader = cmd.ExecuteReader()) {
      while (myReader.Read()) {
        splyCd.Items.Add(new comboboxItem(myReader["splyEnm"].ToString(), myReader["splyCd"].ToString()));
      }
      splyCd.SelectedIndex = 0;
    }
     
    cmd.CommandText = "SELECT nationCd,nationENm FROM tblNation order by nationENm";
    using(var myReader = cmd.ExecuteReader()) {
      while (myReader.Read()) {
        nationCd.Items.Add(new comboboxItem(myReader["nationENm"].ToString(), myReader["nationCd"].ToString()));
      }
      nationCd.SelectedIndex = 0;
    }
    dbConn.Dispose();
    dbConn.Close();
  } catch (Exception b) {
    MessageBox.Show(b.ToString());
  }
}
 
 
public class comboboxItem {
    public string Text {
        get;
        set;
    }
    public object Value {
        get;
        set;
    }
 
    public override string ToString() {
        return Text;
    }
    public comboboxItem(string text, object value) {
        Text = text;
        Value = value;
    }
}


* Set : 값 지정하기

nationCd.Text = "KR";



* Get : 선택 값 가져오기 

comboboxItem item;
item = (comboboxItem)nationCd.SelectedItem;
string nationValue = item.Value.ToString();


?

  1. WindowsForms Application DataGridView

    Date2013.07.05 CategoryC# Bykay Views2646
    Read More
  2. ComboBox ReadOnly 속성

    Date2013.07.08 CategoryC# Bykay Views3292
    Read More
  3. comboBox 디비 데이터로 채워넣기

    Date2013.07.08 CategoryC# Bykay Views3279
    Read More
  4. dataGridView 내용 정렬 ( DefaultCellStyle , ColumnHeadersDefaultCellStyle )

    Date2013.07.08 CategoryC# Bykay Views5877
    Read More
  5. MDI 폼 이동 및 시작 폼 설정하기

    Date2013.07.09 CategoryC# Bykay Views3429
    Read More
  6. 최근에 사용한 프로젝트 삭제

    Date2013.07.10 CategoryVS Bykay Views2513
    Read More
  7. SqlCommand 재사용(Reuse) 하기

    Date2013.07.10 CategoryC# Bykay Views3926
    Read More
  8. ComboBox Option ( Add , Set , Get )

    Date2013.07.10 CategoryC# Bykay Views16007
    Read More
  9. DataGridView 에서 열 숨기기

    Date2013.07.22 CategoryC# Bykay Views3332
    Read More
  10. DataGridView 에서 Cells 값 Null/Empty 체크하기

    Date2013.07.22 CategoryC# Bykay Views9552
    Read More
  11. TextBox 에서 줄바꿈 넣기

    Date2013.07.22 CategoryC# Bykay Views10450
    Read More
  12. Confirm Massage 창 띄우기

    Date2013.07.22 CategoryC# Bykay Views13001
    Read More
  13. 프로그래밍 방식으로 버튼의 Click 이벤트 호출

    Date2013.07.23 CategoryC# Bykay Views2730
    Read More
  14. MDI 폼 한번에 모두 닫기

    Date2013.07.25 CategoryC# Bykay Views2824
    Read More
  15. 폼에서 새폼 열고 자신은 완전히 닫기.

    Date2013.07.26 CategoryC# Bykay Views7635
    Read More
  16. TextBox KeyEvent 엔터 이벤트 실행하기

    Date2013.07.26 CategoryC# Bykay Views3840
    Read More
  17. C# 외부 프로그램 실행하기 ( Process.Start )

    Date2013.08.06 CategoryC# Bykay Views10568
    Read More
  18. 엑셀 내보내기 , Exporting DataGridview To Excel

    Date2013.08.08 CategoryC# Bykay Views5117
    Read More
  19. 화면 캡쳐하기

    Date2013.09.02 CategoryC# Bykay Views4060
    Read More
  20. DataGridViewComboBoxColumn Change 이벤트 Value 값 가져오기

    Date2013.09.02 CategoryC# Bykay Views5401
    Read More
Board Pagination Prev 1 2 Next
/ 2