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,038

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


 

[.NET] ต้องการจะเลือกรายการจาก 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 : 2090 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,059 )
บทความ ( 838 )

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

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

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

Code (VB.NET)
001.Imports System.Windows.Forms
002. 
003.Public Class Form1
004.    Inherits System.Windows.Forms.Form
005. 
006.    Public Sub New()
007.        MyBase.New()
008.        InitializeComboBox()
009.        InitializeTextBox()
010.        Me.Label1 = New System.Windows.Forms.Label
011.        Me.SuspendLayout()
012.        Me.Label1.Location = New System.Drawing.Point(8, 24)
013.        Me.Label1.Name = "Label1"
014.        Me.Label1.Size = New System.Drawing.Size(120, 32)
015.        Me.Label1.TabIndex = 1
016.        Me.Label1.Text = "Use drop-down to choose a name:"
017.        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
018.        Me.ClientSize = New System.Drawing.Size(292, 266)
019.        Me.Controls.Add(Me.Label1)
020.        Me.Name = "Form1"
021.        Me.Text = "Form1"
022.        Me.ResumeLayout(False)
023.    End Sub
024. 
025.    Shared Sub Main()
026.        Application.Run(New Form1)
027.    End Sub
028. 
029. 
030.    Friend WithEvents Label1 As System.Windows.Forms.Label
031. 
032. 
033. 
034. 
035.    ' Declare and initialize the text box.
036.    ' This text box text will be update programmatically. The user is not
037.    ' allowed to update it, so the ReadOnly property is set to true.
038.    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
039. 
040.    Private Sub InitializeTextBox()
041.        Me.TextBox1 = New System.Windows.Forms.TextBox
042.        Me.TextBox1.ScrollBars = ScrollBars.Vertical
043.        Me.TextBox1.Location = New System.Drawing.Point(64, 128)
044.        Me.TextBox1.Multiline = True
045.        Me.TextBox1.Name = "TextBox1"
046.        Me.TextBox1.ReadOnly = True
047.        Me.TextBox1.Size = New System.Drawing.Size(184, 120)
048.        Me.TextBox1.TabIndex = 4
049.        Me.TextBox1.Text = "Employee and Number of Awards:"
050.        Me.Controls.Add(Me.TextBox1)
051.    End Sub
052. 
053. 
054.    ' Declare comboBox1 as a ComboBox.
055.    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
056. 
057.    ' This method initializes the combo box, adding a large string
058.    ' array but limiting the drop-down size to six rows so the combo box
059.    ' doesn't cover other controls when it expands.
060.    Private Sub InitializeComboBox()
061.        Me.ComboBox1 = New System.Windows.Forms.ComboBox
062.        Dim employees() As String = New String() {"Hamilton, David", _
063.            "Hensien, Kari", "Hammond, Maria", "Harris, Keith", _
064.            "Henshaw, Jeff D.", "Hanson, Mark", "Harnpadoungsataya, Sariya", _
065.            "Harrington, Mark", "Harris, Keith", "Hartwig, Doris", _
066.            "Harui, Roger", "Hassall, Mark", "Hasselberg, Jonas", _
067.            "Harnpadoungsataya, Sariya", "Henshaw, Jeff D.", "Henshaw, Jeff D.", _
068.            "Hensien, Kari", "Harris, Keith", "Henshaw, Jeff D.", _
069.            "Hensien, Kari", "Hasselberg, Jonas", "Harrington, Mark", _
070.            "Hedlund, Magnus", "Hay, Jeff", "Heidepriem, Brandon D."}
071. 
072.        ComboBox1.Items.AddRange(employees)
073.        Me.ComboBox1.Location = New System.Drawing.Point(136, 32)
074.        Me.ComboBox1.IntegralHeight = False
075.        Me.ComboBox1.MaxDropDownItems = 5
076.        Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
077.        Me.ComboBox1.Name = "ComboBox1"
078.        Me.ComboBox1.Size = New System.Drawing.Size(136, 81)
079.        Me.ComboBox1.TabIndex = 0
080.        Me.Controls.Add(Me.ComboBox1)
081.    End Sub
082. 
083. 
084. 
085.    ' This method is called when the user changes his or her selection.
086.    ' It searches for all occurrences of the selected employee's
087.    ' name in the Items array and adds the employee's name and
088.    ' the number of occurrences to TextBox1.Text.
089. 
090.    ' CAUTION   This code exposes a known bug: If the index passed to the
091.    ' FindStringExact(searchString, index) method is the last index
092.    ' of the array, the code throws an exception.
093.    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _
094.        ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
095. 
096.        Dim comboBox As comboBox = CType(sender, comboBox)
097. 
098.        ' Save the selected employee's name, because we will remove
099.        ' the employee's name from the list.
100.        Dim selectedEmployee = CType(ComboBox1.SelectedItem, String)
101. 
102.        Dim count As Integer = 0
103.        Dim resultIndex As Integer = -1
104. 
105.        ' Call the FindStringExact method to find the first
106.        ' occurrence in the list.
107.        resultIndex = ComboBox1.FindStringExact(ComboBox1.SelectedItem)
108. 
109.        ' Remove the name as it is found, and increment the found count.
110.        ' Then call the FindStringExact method again, passing in the index of the
111.        ' current found item so the search starts there instead of
112.        ' at the beginning of the list.
113.        While (resultIndex <> -1)
114.            ComboBox1.Items.RemoveAt(resultIndex)
115.            count += 1
116.            resultIndex = ComboBox1.FindStringExact _
117.            (selectedEmployee, resultIndex)
118.        End While
119. 
120.        ' Update the text in Textbox1.
121.        TextBox1.Text = TextBox1.Text & Microsoft.VisualBasic.vbCrLf _
122.            & selectedEmployee & ": " & count
123.    End Sub
124. 
125.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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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