Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Two related listBoxes question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guy Dillen - 04 Dec 2004 20:40 GMT
I want to relate 2 listBoxes. Although during the filling of the first
listBox1; the event SelectedIndexChanged already fires (this is not the
purpose). The event should only fire when a select an item in listBox1.
How can i avoid that the event fires too early?

...
private void button3_Click(object sender, System.EventArgs e)
{

DataSet ds = new DataSet();

DataAdapter da = null;

string SQLcom = "SELECT toto, id FROM table";

da = new DataAdapter(SQLcom, conn);

da.Fill(ds, "table");

listBox1.DataSource = ds.Tables["table"];

listBox1.ValueMember = "id";

listBox1.DisplayMember = "toto";

listBox1.SelectedIndex = -1;

}

private void listBox1_SelectedIndexChanged(object sender, System.EventArgs
e)

{

DataSet ds = new DataSet();

DataAdapter da = null;

string SQLcom = "SELECT tata, id FROM table2";

da = new DataAdapter(SQLcom, conn);

da.Fill(ds, "table2");

listBox2.DataSource = ds.Tables["table2"];

listBox2.ValueMember = "id";

listBox2.DisplayMember = "tata";

listBox2.SelectedIndex = -1;

}
Claes Bergefall - 06 Dec 2004 08:48 GMT
Turn of the eventhandler during loading and add it back
when done,

listBox1.SelectedIndexChanged -= new
EventHandler(listBox1_SelectedIndexChanged)
...
listBox1.SelectedIndexChanged += new
EventHandler(listBox1_SelectedIndexChanged)

or use a flag that you check at the beginning
of listBox1_SelectedIndexChanged

  /claes

> I want to relate 2 listBoxes. Although during the filling of the first
> listBox1; the event SelectedIndexChanged already fires (this is not the
[quoted text clipped - 49 lines]
>
> }
Guy Dillen - 06 Dec 2004 11:56 GMT
Ok thx for the info.

I suppose this is the correct way to achive this (=relating/linking 2
listBoxes)? Or is this way not the correct one?

Guy

> Turn of the eventhandler during loading and add it back
> when done,
[quoted text clipped - 64 lines]
>>
>> }
Guy Dillen - 06 Dec 2004 13:05 GMT
Thanks for your help, it works.

One more question:
is this the correct way to achive this (realting/linking listBoxes)? Or are
there other more used methods to achieve this?

Guy

> Turn of the eventhandler during loading and add it back
> when done,
[quoted text clipped - 64 lines]
>>
>> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.