 |
|
สอบถามการใช้ Combobox ใน Datagridview ถ้าเลือกจาก Combobox แล้วให้ทำคำสั่งที่เขียน หรือแสดงข้อความอีกช่องครับ |
|
 |
|
|
 |
 |
|
ลองดูใน event ตามนี้ครับ
CellEndEdit
CellValueChanged
|
 |
 |
 |
 |
Date :
2015-08-20 16:18:04 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ตัวด้านล่างนี้เลยครับ น่าจะโอเค
Code
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged);
combo.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);
}
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox cb = (ComboBox)sender;
string item = cb.Text;
if (item != null)
MessageBox.Show(item);
}
|
 |
 |
 |
 |
Date :
2015-08-20 16:43:49 |
By :
Thaidevelopment.NET |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub dataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)
Dim combo As ComboBox = TryCast(e.Control, ComboBox)
If combo IsNot Nothing Then
combo.SelectedIndexChanged -= New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
combo.SelectedIndexChanged += New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
End If
End Sub
Private Sub ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim cb As ComboBox = DirectCast(sender, ComboBox)
Dim item As String = cb.Text
If item IsNot Nothing Then
MessageBox.Show(item)
End If
End Sub
|
 |
 |
 |
 |
Date :
2015-08-21 08:29:49 |
By :
Thaidevelopment.NET |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มัน Error ตรงนี้ครับ
combo.SelectedIndexChanged
Code (VB.NET)
Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
Dim combo As ComboBox = TryCast(e.Control, ComboBox)
If combo IsNot Nothing Then
combo.SelectedIndexChanged -= New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
combo.SelectedIndexChanged += New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
End If
End Sub
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim cb As ComboBox = DirectCast(sender, ComboBox)
Dim item As String = cb.Text
If item IsNot Nothing Then
MessageBox.Show(item)
End If
End Sub
|
ประวัติการแก้ไข 2015-09-28 09:28:58
 |
 |
 |
 |
Date :
2015-09-28 09:27:55 |
By :
TheCom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ละครับ
เปลี่ยนจาก -= , += เป็น RemoveHandler , AddHandler
Code (VB.NET)
Private Sub ComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs)
Dim cb As ComboBox = DirectCast(sender, ComboBox)
Dim item As String = cb.Text
MsgBox(item)
If item IsNot Nothing Then
Exit Sub
Else
Dim FrmFinStockSeach As New FrmFineStockShearch
FrmFinStockSeach.ShowDialog()
End If
End Sub
Private Sub DGV1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DGV1.EditingControlShowing
Dim Cbo As ComboBox = TryCast(e.Control, ComboBox)
If Cbo IsNot Nothing Then
RemoveHandler Cbo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)
AddHandler Cbo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)
End If
End Sub
|
 |
 |
 |
 |
Date :
2015-09-28 10:41:17 |
By :
TheCom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|