Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Few things I don't understand
Message
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01400762
Message ID:
01400776
Views:
59
This message has been marked as a message which has helped to the initial question of the thread.
Please look at the following link, there is an example to bind a ComboBox to DataTable and binding TextBoxes:

Zurück
Data Binding in .NET / C# Windows Forms
http://www.akadia.com/services/dotnet_databinding.html

Some part of document as mentioned above:

Binding to a Combobox
The Combobox doesn't have a DataMember property - instead it has a DisplayMember and ValueMember property:

* The DisplayMember of a Combobox gets or sets a string that specifies the property of the data source whose contents you want to display.

* The ValueMember property determines which value gets moved into the SelectedValue of the Combo Box. In the example, whenever the user selects a Customer by "Customers.CompanyName", the SelectedValue is the "Customers.CustomerID". Whenever the SelectedValue changes, the data-binding moves the new value into the Customer object.

// Setup the combobox view and display-, value member
cbCust.DataSource = dsView;
cbCust.DisplayMember = "Customers.CompanyName";
cbCust.ValueMember = "Customers.CustomerID";


// Text Columns Databinding
txtContact.DataBindings.Add("Text",dsView,"Customers.ContactName");
txtPhoneNo.DataBindings.Add("Text",dsView,"Customers.Phone");
txtFaxNo.DataBindings.Add("Text",dsView,"Customers.Fax");

2- "Why do I need to convert the result into the two fields dictionary and then using loop through the dictionary to bind the combobox"
Just I didn't understand why you have to use dictionary to bind the Combobox, sorry about that, but I had something about Dictionary
which is in the following link: (may be it gives idea but it's not working around GUID)
http://iborn2code.blogspot.com/2009/05/c-generic-dictionary-types-dictionary.html

HTH


> I have a method in my BL that returns a datatable with many columns. I want to have my combobox to be bound to the table and being able to return selected row and bind textboxes to the information selected in this row.
>
> My questions are
>
> 1. Why do I need to convert the result into the two fields dictionary (one being description and another being Guid.ToString()) and then using loop through the dictionary to bind the combobox - can I bind directly to the datatable - what are implications for the mobile app?
>
> 2. Using dictionary this way I can not get back my item
>
> Here is what I tried:
>
> private void RefreshSelectedItemInfo()
> {
> string SelectedItem = this.cboItems.Text.Trim();
> if (SelectedItem!="")
> {
> string ItemPK;
> _inventoryEntries.TryGetValue(SelectedItem, out ItemPK);
>
> InventoryDS.ItemsDataTable dt = _inventoryBiz.GetDataByInventoryKey(ItemPK); //ItemPK should be Guid in the method - I can not cast to Guid
> }
> }
>
> I can use ItemNo as the second string (Pk) in my dictionary instead - I have another method to get item info by ItemNo, but all of this sounds like very strange, complex and convoluted way to get my info - should I go ahead changing my dictionary or there is a simpler way around?
Previous
Reply
Map
View

Click here to load this message in the networking platform