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 / July 2006

Tip: Looking for answers? Try searching our database.

Currency Manager returns last ComboBox item row

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom - 06 Jul 2006 09:37 GMT
I've made something like that:

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

{

CurrencyManager cm = (CurrencyManager)
this.BindingContext[((ComboBox)sender).DataSource];

DataRow dr = ((DataRowView) cm.Current).Row;

MessageBox.Show( dr[0].ToString());

}

comboBox1 is binded like this:

DataTable dt = new DataTable("table");

DataColumn ix = new DataColumn("ix",System.Type.GetType("System.String"));

DataColumn iy = new DataColumn("iy",System.Type.GetType("System.String"));

DataRow dr ;

dt.Columns.Add(ix);

dt.Columns.Add(iy);

dr = dt.NewRow();

dr[0] = "asterix";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[0] = "abladabla";

dt.Rows.Add(dr);

comboBox1.DataSource = dt;

comboBox1.DisplayMember = "ix";

The result is that if I choose abladabla from combobox, the sterix value is
displayed in a messagebox -> The last selected row is returned by the code
in SelectedIndexChanged. Don't know how to make this work "normal". Simply:
I choose asterix -> it displays asterix, I choose abladabla or whatsoever,
it displays it.
Dave Sexton - 08 Jul 2006 02:19 GMT
Hi Tom,

No need for a CurrencyManager.  If you only want the selected text, then use
((ComboBox) sender).SelectedText, otherwise you can obtain the selected row
like this:

ComboBox comboBox1 = (ComboBox) sender;

DataRowView selectedRowView = (DataRowView) comboBox1.SelectedItem;

MessageBox.Show(selectedRowView[0]);

HTH

> I've made something like that:
>
[quoted text clipped - 47 lines]
> Simply: I choose asterix -> it displays asterix, I choose abladabla or
> whatsoever, it displays it.

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.