Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MmPicker and int fields
Message
 
À
25/01/2006 07:40:29
Rick Forbes
Brotherhood of Maintenance of Way Employ
Royal Oak, Michigan, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01089499
Message ID:
01090720
Vues:
16
Rick,

>It's a compile time error. Here is the actual error:
>
>Error 4 Cannot convert type 'string' to 'int' H:\MM\Voting System\Voting System\ElectionMaintenanceForm.cs 39 64 Voting System
>
>
>Here is the code:
>
> private void pckElection_ItemSelected(object sender, mmPickerItemSelectedEventArgs e)
> {
> this.dsBallot = this.oBallot.GetBallotByElectionPK((int)this.pckElection.Text);
> this.btnNew.Enabled = true;
> }

There are a few issues here

  1. 1. In C#, if you want to convert a string to an integer, you must use the Parse command. For example:
    int.Parse(this.pckElection.Text);
  2. You mentioned there are two columns in the table, OfficePK and Title. Typically, you want to display the description in the picker text box and NOT display the OfficePK (it's usually a system-generated key).

    If this is the case, you don't want to grab the OfficePK value from the textbox, but rather derive it from the event arguments in the PickList's ItemSelected() event handler. All items selected in a picklist are stored in the event arguments's dsSelectedItems property. For example (using an untyped data approach):
    int OfficePK = (int)e.dsSelectedItems.Tables[0].Rows[0]["OfficePK"];
    this.dsOffice = this.oOffice.GetOfficeByOfficePK(OfficePK);

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