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)
1245POPO3/26/201418500Http 프로토콜 관련 질문 입니다. [1]
1244(non...3/26/201418249(글쓴이의 요청으로 삭제합니다.) [1]
1241(non...3/22/201421795(글쓴이의 요청으로 삭제합니다.) [4]
1240이석주3/21/201424643인터넷 익스플로러가 hang이 걸리는 현상 문의 [1]파일 다운로드1
1238(non...3/13/201418614(글쓴이의 요청으로 삭제합니다.) [2]
1237(non...3/11/201418596(글쓴이의 요청으로 삭제합니다.) [2]
1236(non...3/11/201419514(글쓴이의 요청으로 삭제합니다.) [2]
1235(non...3/10/201418286(글쓴이의 요청으로 삭제합니다.) [2]
1234(non...3/10/201422040(글쓴이의 요청으로 삭제합니다.) [3]
1233(non...3/9/201419736(글쓴이의 요청으로 삭제합니다.) [4]
1232(non...3/8/201418660(글쓴이의 요청으로 삭제합니다.) [2]
1231(non...3/7/201419768(글쓴이의 요청으로 삭제합니다.) [9]
1230POCO3/7/201420152쓰레드 안에서 DependencyProperty get, set시 또 다른 스레드 오류.. [1]
1229(non...3/6/201421022(글쓴이의 요청으로 삭제합니다.) [11]
1228POCO3/6/201418965안녕하세요. 질문이 있습니다. [1]
1226김형진3/4/201429121안녕하세요 windows azure에 관해 질문했던 사람입니다. [2]
1224(non...3/3/201424590(글쓴이의 요청으로 삭제합니다.) [11]
1223sadf...3/3/201418930아래 질문에 답변 감사드립니다. 한가지 더 궁금한점이 있어 질문드립니다. [1]
1222(non...3/2/201419247(글쓴이의 요청으로 삭제합니다.) [4]
1221(non...3/1/201419754(글쓴이의 요청으로 삭제합니다.) [2]
1220Until2/28/201418131질문드립니다. [1]
1219이성환2/28/201417493string.Join()과 Enumerable.Aggregate()의 차이가 궁금합니다. [2]파일 다운로드1
1218김형진2/25/201419432안녕하세요. window azure에 대해서 질문이 있어서 문의 드립니다 [4]
1217(non...2/23/201419981(글쓴이의 요청으로 삭제합니다.) [1]
1215아리수2/20/201423449C# 공부하면서 WPF에 대한 질문. [2]
1214조광훈2/20/201421462IIS8 응용프로그램 풀 관련 질문 드립니다. [2]파일 다운로드1
... 46  47  48  49  50  51  52  53  54  55  56  [57]  58  59  60  ...