Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return int value from mmPicker ?
Message
 
À
28/04/2006 22:26:16
Donald Lowrey
Data Technology Corporation
Las Vegas, Nevada, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01117746
Message ID:
01117751
Vues:
14
>As a VFP developer, I am still stumbling in C#. I am hoping someone will save me another day of going nowhere. I know enough to realize that there is a fundamental error here, but I don't see where.
>
>mmpicker is on a MM.Net Business form. Setting the usual property values on the picker correctly pops and populates a picklist form, and the selected item is displayed in the picker's textbox. So far so good, Maybe. PicklistDisplayMember is set to a table column name "lastname "and PicklistValueMember is set to column name "conPk". Doesn't the PK value get stored in a mmpicker property?

>
> public ContactEntity GetContactbyPk(Int32 con_pk)
>      {
>      this.GetDataSet("SELECT * FROM Contact WHERE con_pk = @conPk",
>      this.CreateParameter("@conPk", con_pk));
>      return this.Entity;
>      }
>
>Now jumping to the form, the mmPicker's ItemSelected event is raised and the the above method called:
>
>
>private void pckStudent_ItemSelected(object sender, OakLeaf.MM.Main.Windows.Forms.mmPickerItemSelectedEventArgs e)
>       {
>            this.oContact.GetContactbyPk(this.pckStudent.Text);
>       }
>
In the pckStudent_ItemSelected() handler method you are pulling the value from the Text property of a text box. If you hover your mouse pointer over the Text property you will see it is a string. In order to pass the value stored in the Text property to the GetContactByPk() method, you must first convert it to an integer. To do this, you can use the int.Parse() method like this:
this.oContact.GetContactbyPk(int.Parse(this.pckStudent.Text));
Now, all of that said, I'm thinking that the primary key of the item you select probably isn't being stored in the Text property of pckStudent...unless you have it set specifically to do this. The ItemSelected handler method is passed an <>mmPickerItemSelectedEventArgs <>object. You can examine the <>dsSelectedItems <>property of this event argument object to look at all columns of the item selected in the PickList control.

For example:
// Get the DataRow that contains the item selected in the PickList
DataRow Row = e.dsSelectedItems.Tables[0].Rows[0];

// Specify the column name you want to retrieve a value from
int SelectedItemPK = (int)Row["My_PK"];
Best Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform