Microsoft MVP성태의 닷넷 이야기
글쓴 사람
SunNee Dong (clickway at naver.com)
홈페이지
첨부 파일
 

선생님 안녕하세요.
textbox에서 글자 입력 후 textBox1_KeyUp함수에서
listBox1_SelectedIndexChanged 강제로 호출하는 방법 가르쳐주세요
***아래코드를 변형하면 안됩니다***
***아래코드 변형없이,textBox1_KeyUp함수에서listBox1_SelectedIndexChanged 강제 호출입니다***
부탁드립니다. 선생님 답변 기다립니다

namespace MyWinForm
{
   public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
      }
      private void textBox1_KeyUp(object sender, KeyEventArgs e)
      { // textbox 에서 글자 입력 후 textBox1_KeyUp 호출됨
         // textBox1_KeyUp 에서 listBox1_SelectedIndexChanged함수 호출하고 싶습니다
          listBox1.listBox1_SelectedIndexChanged(); //<=======이부분을 모릅니다. private타입입니다
      }
      private void textBox1_TextChanged(object sender, EventArgs e)
      { // textbox 에 글자를 씁니다
           listBox1.SelectedIndexChanged -= new EventHandler(listBox1_SelectedIndexChanged);
           listBox1.SelectedIndex = idx;
           listBox1.SetSelected(idx, true);
           listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
      }
      private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
      {
         int nIndex = listBox1.SelectedIndex;
      }
      private void Form1_Load(object sender, EventArgs e)
      {
         listBox1.Items.Add("Apple");
         listBox1.Items.Add("Banana");
         listBox1.Items.Add("Coconut");
         listBox1.Items.Add("Grape");
         listBox1.SelectedIndex = 1;
      }
   }
}









[최초 등록일: ]
[최종 수정일: 10/10/2024]


비밀번호

댓글 작성자
 



2024-10-10 10시40분
ListBox.SelectedIndexChanged 이벤트를 그 컨트롤의 내부에서 발생시키려면 SelectedIndex 속성에 (현재 설정된 값과 다른) 값을 설정하면 자연스럽게 내부에서 처리가 됩니다.

만약 내부에서의 처리 과정을 건너 뛰고 listBox1_SelectedIndexChanged 이벤트 핸들러 자체를 실행시키고 싶다면 그냥 그 메서드 그대로를 호출하면 됩니다.

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    listBox1_SelectedIndexChanged(this.listBox1, EventArgs.Empty);
}
정성태

... 46  47  48  49  50  51  52  53  54  55  56  [57]  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
1258최세정4/28/201420643안녕하세요~php module 오류로 고민하다가 여기까지 왔네요..ㅜㅜ [2]
1252popo4/21/201420010바인딩 질문입니다. [2]
1251(non...4/20/201424164(글쓴이의 요청으로 삭제합니다.) [11]
1249홍용규4/17/201424377app.config 파일 관련 질문 있습니다. [2]
1246(non...3/30/201420148(글쓴이의 요청으로 삭제합니다.) [1]
1245POPO3/26/201419514Http 프로토콜 관련 질문 입니다. [1]
1244(non...3/26/201419169(글쓴이의 요청으로 삭제합니다.) [1]
1241(non...3/22/201422536(글쓴이의 요청으로 삭제합니다.) [4]
1240이석주3/21/201425430인터넷 익스플로러가 hang이 걸리는 현상 문의 [1]파일 다운로드1
1238(non...3/13/201419570(글쓴이의 요청으로 삭제합니다.) [2]
1237(non...3/11/201419450(글쓴이의 요청으로 삭제합니다.) [2]
1236(non...3/11/201420347(글쓴이의 요청으로 삭제합니다.) [2]
1235(non...3/10/201418829(글쓴이의 요청으로 삭제합니다.) [2]
1234(non...3/10/201423452(글쓴이의 요청으로 삭제합니다.) [3]
1233(non...3/9/201421171(글쓴이의 요청으로 삭제합니다.) [4]
1232(non...3/8/201419883(글쓴이의 요청으로 삭제합니다.) [2]
1231(non...3/7/201420809(글쓴이의 요청으로 삭제합니다.) [9]
1230POCO3/7/201421223쓰레드 안에서 DependencyProperty get, set시 또 다른 스레드 오류.. [1]
1229(non...3/6/201422480(글쓴이의 요청으로 삭제합니다.) [11]
1228POCO3/6/201420082안녕하세요. 질문이 있습니다. [1]
1226김형진3/4/201430323안녕하세요 windows azure에 관해 질문했던 사람입니다. [2]
1224(non...3/3/201426073(글쓴이의 요청으로 삭제합니다.) [11]
1223sadf...3/3/201420112아래 질문에 답변 감사드립니다. 한가지 더 궁금한점이 있어 질문드립니다. [1]
1222(non...3/2/201420188(글쓴이의 요청으로 삭제합니다.) [4]
1221(non...3/1/201420874(글쓴이의 요청으로 삭제합니다.) [2]
1220Until2/28/201419354질문드립니다. [1]
... 46  47  48  49  50  51  52  53  54  55  56  [57]  58  59  60  ...