Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ต้องการจะเลือกรายการจาก Combo box ลง datagridview รบกวนชี้แนะด้วยครับผม



 

ต้องการจะเลือกรายการจาก Combo box ลง datagridview รบกวนชี้แนะด้วยครับผม

 



Topic : 079249



โพสกระทู้ ( 33 )
บทความ ( 0 )



สถานะออฟไลน์




คือต้องการจะ Select ข้อมูลจาก Combobox แล้วให้มาแสดงใน Datagridview จะต้องเขียน Code อย่างไรครับผมรบกวนพี่ๆแนะนำด้วยครับ



Tag : ASP.NET, VB.NET









ประวัติการแก้ไข
2012-06-01 13:38:38
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-06-01 13:37:59 By : kakeruna View : 1940 Reply : 2
 

 

No. 1



โพสกระทู้ ( 31 )
บทความ ( 0 )



สถานะออฟไลน์


datagridview1.rows(0).cell(0).value = combobox1.items(combobox1.selectedindex)

ประมาณนี้อ่ะครับ ผมตจำโค้ดไม่ค่อยได้






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-01 16:43:28 By : Projectsup
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ComboBox.SelectedIndexChanged ใช้ Event ตัวนี้ครับ แล้วเอาค่าที่ได้ไป BindData ลงใน GridView ครับ ลองรันดูตัวอย่างนี่ครับ

Code (VB.NET)
Imports System.Windows.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()
        InitializeComboBox()
        InitializeTextBox()
        Me.Label1 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        Me.Label1.Location = New System.Drawing.Point(8, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 32)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Use drop-down to choose a name:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub

    Shared Sub Main()
        Application.Run(New Form1)
    End Sub


    Friend WithEvents Label1 As System.Windows.Forms.Label




    ' Declare and initialize the text box.
    ' This text box text will be update programmatically. The user is not 
    ' allowed to update it, so the ReadOnly property is set to true.
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

    Private Sub InitializeTextBox()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox1.ScrollBars = ScrollBars.Vertical
        Me.TextBox1.Location = New System.Drawing.Point(64, 128)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ReadOnly = True
        Me.TextBox1.Size = New System.Drawing.Size(184, 120)
        Me.TextBox1.TabIndex = 4
        Me.TextBox1.Text = "Employee and Number of Awards:"
        Me.Controls.Add(Me.TextBox1)
    End Sub


    ' Declare comboBox1 as a ComboBox.
    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

    ' This method initializes the combo box, adding a large string 
    ' array but limiting the drop-down size to six rows so the combo box
    ' doesn't cover other controls when it expands.
    Private Sub InitializeComboBox()
        Me.ComboBox1 = New System.Windows.Forms.ComboBox
        Dim employees() As String = New String() {"Hamilton, David", _
            "Hensien, Kari", "Hammond, Maria", "Harris, Keith", _
            "Henshaw, Jeff D.", "Hanson, Mark", "Harnpadoungsataya, Sariya", _
            "Harrington, Mark", "Harris, Keith", "Hartwig, Doris", _
            "Harui, Roger", "Hassall, Mark", "Hasselberg, Jonas", _
            "Harnpadoungsataya, Sariya", "Henshaw, Jeff D.", "Henshaw, Jeff D.", _
            "Hensien, Kari", "Harris, Keith", "Henshaw, Jeff D.", _
            "Hensien, Kari", "Hasselberg, Jonas", "Harrington, Mark", _
            "Hedlund, Magnus", "Hay, Jeff", "Heidepriem, Brandon D."}

        ComboBox1.Items.AddRange(employees)
        Me.ComboBox1.Location = New System.Drawing.Point(136, 32)
        Me.ComboBox1.IntegralHeight = False
        Me.ComboBox1.MaxDropDownItems = 5
        Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(136, 81)
        Me.ComboBox1.TabIndex = 0
        Me.Controls.Add(Me.ComboBox1)
    End Sub



    ' This method is called when the user changes his or her selection.
    ' It searches for all occurrences of the selected employee's
    ' name in the Items array and adds the employee's name and 
    ' the number of occurrences to TextBox1.Text.

    ' CAUTION   This code exposes a known bug: If the index passed to the 
    ' FindStringExact(searchString, index) method is the last index 
    ' of the array, the code throws an exception.
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        Dim comboBox As comboBox = CType(sender, comboBox)

        ' Save the selected employee's name, because we will remove
        ' the employee's name from the list.
        Dim selectedEmployee = CType(ComboBox1.SelectedItem, String)

        Dim count As Integer = 0
        Dim resultIndex As Integer = -1

        ' Call the FindStringExact method to find the first 
        ' occurrence in the list.
        resultIndex = ComboBox1.FindStringExact(ComboBox1.SelectedItem)

        ' Remove the name as it is found, and increment the found count. 
        ' Then call the FindStringExact method again, passing in the index of the
        ' current found item so the search starts there instead of 
        ' at the beginning of the list.
        While (resultIndex <> -1)
            ComboBox1.Items.RemoveAt(resultIndex)
            count += 1
            resultIndex = ComboBox1.FindStringExact _
            (selectedEmployee, resultIndex)
        End While

        ' Update the text in Textbox1.
        TextBox1.Text = TextBox1.Text & Microsoft.VisualBasic.vbCrLf _
            & selectedEmployee & ": " & count
    End Sub

End Class

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-01 17:11:57 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการจะเลือกรายการจาก Combo box ลง datagridview รบกวนชี้แนะด้วยครับผม
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่