 |
|
[มือใหม่] ได้สร้างGroupboxไว้โดยข้างในมีปุ่มradio button ให้เลือก ซึ่งถ้าเลือกปุ่มไหน ก็จะโชว์labelและtextbox ของปุ่มนั้น ทำได้หรือไม่ |
|
 |
|
|
 |
 |
|
enable,disible ตอนคลิกครับ บ้านๆๆสุดแระ
|
 |
 |
 |
 |
Date :
2015-07-05 09:20:42 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือทำให้เป็นenabled ทั้งคู่คือ เมื่อเลือกหัวข้อแบบคี่ จะโชว์textboxของแบบคี่มา ส่วนtextboxของแบบคู่จะไม่สามารถกรอกได้
?ทำไมครั้งแรกเมื่อเลือกหัวข้อไหน จะโชว์textboxทั้ง2อัน แต่พอครั้งที่2 กลับได้
|
ประวัติการแก้ไข 2015-07-06 05:38:45
 |
 |
 |
 |
Date :
2015-07-05 09:45:36 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
ตามนี้ครับ
private void ControlItem(bool la1, bool Text1, bool la2, bool Text2)
{
label1.Enabled = la1;
textBox1.Enabled = Text1;
label2.Enabled = la2;
textBox2.Enabled = Text2;
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Enabled = true;
textBox1.Enabled = true;
label2.Enabled = true;
textBox2.Enabled = true;
}
private void radioButton1_Click(object sender, EventArgs e)
{//แบบคู่
if (radioButton1.Checked == true)
{
ControlItem(false, false, true, true);
}
}
private void radioButton2_Click(object sender, EventArgs e)
{//แบบคี่
if (radioButton2.Checked == true)
{
ControlItem(true, true, false, false);
}
}
|
 |
 |
 |
 |
Date :
2015-07-06 16:44:23 |
By :
as76157432 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วจะสร้างปุ่มตกลงและยกเลิกอย่างไร?
โดยปุ่มตกลงจะบันทึกลงฐานข้อมูล แบบไปใส่ในFieldนั้นและระบุRowว่าถึงแค่ไหน และ
ปุ่มยกเลิกทำให้ตัวเลขที่กรอกนั้นหายไป
|
 |
 |
 |
 |
Date :
2015-07-06 21:59:25 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จุดประสงค์ ใช้เพื่อทำอะไร
|
 |
 |
 |
 |
Date :
2015-07-06 22:03:47 |
By :
Yoh |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าถามถึงปุ่มตกลง ก็นำจำนวนที่กรอกในtextbox บันทึกลงฟิลด์จำนวนของฐานข้อมูล
|
 |
 |
 |
 |
Date :
2015-07-07 00:09:09 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ตัวอย่างบ้านๆแบบนี้ไม่ทราบว่าเปนไปตามที่อยากได้ป่ะครับ
ง่ายๆ เริ่มต้นที่การออกแบบฐานข้อมูล แล้วก็ลง datagrid แบบบ้านๆ โดยใช้เปน DataGridViewComboBoxColumn
user เองก็เข้าใจง่าย programer เองก็เขียนง่าย
|
 |
 |
 |
 |
Date :
2015-07-07 09:08:02 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ใช่อะ
จากรูปคือนำจำนวนที่กรอกนี้ ไปใส่ในคอลัมจำนวนของฐานข้อมูล(กดปุ่มตกลง) ซึ่งถ้า
เลขที่กรอกเป็นเลขคี่ ก็จะใส่ในตรงกับtypeเลขคี่
|
ประวัติการแก้ไข 2015-07-07 11:32:54
 |
 |
 |
 |
Date :
2015-07-07 11:31:40 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูโค้ดแบบเต็มๆ หน่อยได้มั้ย (vb2012 และaccess/2007)
|
 |
 |
 |
 |
Date :
2015-07-07 20:50:35 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

โค๊ดบ้านๆ ครับ
Code (VB.NET)
Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
DataGridView1(0, e.RowIndex).Value = IIf(Convert.ToInt32(DataGridView1(1, e.RowIndex).Value) Mod 2 = 0, "แบบคู่", "แบบคี่")
End Sub
|
 |
 |
 |
 |
Date :
2015-07-08 08:42:16 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วปุ่มตกลงที่ทำให้ ตัวเลขมายัง Column2 เขียนโค้ดยังไง
|
 |
 |
 |
 |
Date :
2015-07-08 08:58:52 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือมันต้องการให้เป็นแบบนั้น โดยเริ่มจาก เลือกหัวข้อในradio(จากนั้นข้อมูลจะโชว์ในdatadridview)>เลือกประเภท>กรอกจำนวน>กดปุ่มตกลง(คือเพิ่มลงdatagridviewและบันทึกลงฐานข้อมูลพร้อมกัน)
คุณช่วยเขียนโค้ดในส่วนของป่มตกลงให้ดูหน่อยได้หรือป่าว
|
ประวัติการแก้ไข 2015-07-08 09:26:31
 |
 |
 |
 |
Date :
2015-07-08 09:22:47 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หน้าตาของโปรแกรม

โดยข้อมูลที่โชว์ในdatagridview มีคราวๆดังนี้
ID Product Type NUM
1 ส้ม 1
2 แตงโม 1
3 ผักชี 2
4 คะน้า 2
5 กะหล่ำ 2
โค้ด
Code (VB.NET)
Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Dim con As New OleDbConnection
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
Label1.Enabled = True
TextBox1.Enabled = True
Label2.Enabled = False
TextBox2.Enabled = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
Label1.Enabled = False
TextBox1.Enabled = False
Label2.Enabled = True
TextBox2.Enabled = True
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\admim\Documents\ฐานข้อมูล31.accdb"
con.Open()
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter("SELECT * FROM tb_Products", con)
da.Fill(dt)
Me.DataGridView1.DataSource = dt.DefaultView
con.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Enabled = True
TextBox1.Enabled = True
Label2.Enabled = True
TextBox2.Enabled = True
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\admim\Documents\ฐานข้อมูล31.accdb"
con.Open()
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter("SELECT * FROM tb_DD", con)
da.Fill(dt)
Me.DataGridView1.DataSource = dt.DefaultView
con.Close()
End Sub
End Class
|
ประวัติการแก้ไข 2015-07-08 11:47:52
 |
 |
 |
 |
Date :
2015-07-08 11:46:21 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ตามนั้นๆๆๆ
มีตัวอย่างการใช้งานป่ะครับ
อ๊อ อยากทราบ คอนเซป ของงานนี้อ่าครับ
เพราะเหมือนจะใช้แค่ datagrid ก็น่าจะใช้ได้ง่ายกว่าแบบนี้อ่าครับ(อันนี้แค่เดาเอาอ่าครับ)
|
 |
 |
 |
 |
Date :
2015-07-08 13:56:59 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดบ้านๆแม้จะไม่ช่วยไรมาก แต่ก็ทำให้โค๊ดกระชับขึ้นดูง่ายด้วยครับ
Code (VB.NET)
Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Dim con As New OleDbConnection
Private Sub SetDisplay(chk As Boolean)
Label1.Enabled = chk
TextBox1.Enabled = chk
Label2.Enabled = Not chk
TextBox2.Enabled = Not chk
End Sub
Public Sub DisplayDatagrid(sql As String, dgv As DataGridView)
con.Open()
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter(sql, con)
da.Fill(dt)
dgv.DataSource = dt.DefaultView
con.Close()
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
SetDisplay(True)
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
SetDisplay(False)
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
DisplayDatagrid("SELECT * FROM tb_Products", DataGridView1)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\admim\Documents\ฐานข้อมูล31.accdb"
Label1.Enabled = True
TextBox1.Enabled = True
Label2.Enabled = True
TextBox2.Enabled = True
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
DisplayDatagrid("SELECT * FROM tb_DD", DataGridView1)
End Sub
End Class
|
 |
 |
 |
 |
Date :
2015-07-08 14:43:49 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมาก
|
 |
 |
 |
 |
Date :
2015-07-08 18:45:54 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยเพิ่มเติมอีกนิดครับไม่รู้ว่าผมเขียนถูกไหมถ้าผิดก็ขออภัยด้วยครับพึ่งหัดเขียน
Code (VB.NET)
'เมื่อ Form1 เปิดมาสั่งให้ ติ๊ก RadioButton4 [แบบคี่] และเปิดใช้งาน TextBox1 [จำนวนเลขคี่]
'และปิดใช้งาน TextBox2 [จำนวนเลขคู่]
'ส่วน Label1 ไม่ได้ใช้ทำอะไรคงไม่ต้องไปยุ่งกับมัน
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RadioButton4.Checked = True
TextBox1.Enabled = True
RadioButton5.Checked = False
TextBox2.Enabled = False
End Sub
|
ประวัติการแก้ไข 2015-07-08 19:35:52
 |
 |
 |
 |
Date :
2015-07-08 19:34:46 |
By :
เมฆา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|