Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What's wrong with my class
Message
De
02/09/2005 07:40:30
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
02/09/2005 05:21:00
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01046121
Message ID:
01046154
Vues:
18
>I am creating a class that displays student names on a contextmenu. The class exposes a funtion GetStudid, which displays the contextmenu and must return the corresponding studid of the selected student. The problem is I can't get the correct studid. What is returned is the studid of the student that was previously clicked.
>
>I have atteched my code for clarity.
>
>
>Public Class myStudent
>    Public student_name, studid As String
>
>    Private DS As New DataSet
>
>    Sub New()
>        ' POPULATE THE DATASET.  In my program, these data come from an SQL table
>        DS.Tables.Add("students")
>        DS.Tables("students").Columns.Add("studid")
>        DS.Tables("students").Columns.Add("studname")
>
>        Dim dt As DataRow
>
>        dt = DS.Tables("students").NewRow
>        dt.Item("studid") = "2001-00234"
>        dt.Item("studname") = "DOE, JOHN"
>        DS.Tables("students").Rows.Add(dt)
>
>        dt = DS.Tables("students").NewRow
>        dt.Item("studid") = "2002-00230"
>        dt.Item("studname") = "DORRIS, PAUL"
>        DS.Tables("students").Rows.Add(dt)
>
>        dt = DS.Tables("students").NewRow
>        dt.Item("studid") = "2002-00418"
>        dt.Item("studname") = "DJANGO, MANDRID"
>        DS.Tables("students").Rows.Add(dt)
>
>        dt = DS.Tables("students").NewRow
>        dt.Item("studid") = "2001-00994"
>        dt.Item("studname") = "DARRYL, JOSEPH"
>        DS.Tables("students").Rows.Add(dt)
>
>    End Sub
>
>    Public Function GetStudid(ByVal pTextBox As TextBox) As String
>        'Shows a context menu and returns the STUDID of the selected student
>        Dim cm As New ContextMenu
>        Dim mnuItem As MenuItem
>        For Each dr As DataRow In DS.Tables("students").Rows
>            mnuItem = New MenuItem(dr.Item("studname"))
>            AddHandler mnuItem.Click, AddressOf cmEventhandler
>            cm.MenuItems.Add(mnuItem)
>        Next
>        cm.Show(pTextBox, New Point(0, 0))
>    End Function
>
>    Private Sub cmEventhandler(ByVal sender As Object, ByVal e As EventArgs)
>        Dim cm_index = CType(sender, MenuItem).Index
>        studid = DS.Tables("students").Rows(cm_index).Item("studid")
>    End Sub
>End Class
>
>---------------------------------------------------------------------
>This is the main form
>---------------------------------------------------------------------
>
>Public Class Form1
>    Inherits System.Windows.Forms.Form
>
>#Region " Windows Form Designer generated code "
>#End Region
>
>    Dim mystud As New myStudent
>    'A Textbox and a Command Button was placed at design time
>
>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
>        mystud.GetStudid(TextBox1)
>
>        'MsgBox("delay")
>
>        MsgBox(mystud.studid)
>    End Sub
>End Class
>
>
>But if I uncomment the line ['MsgBox("delay")], the code works fine.
>
>Any help would be very much appreciated

I couldn't reproduce what you're seeing. However I created a C# version and (I think this might be) instead of MsgBox() I used MessageBox.Show().
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform