 |
|
จะมีการเปลี่ยนข้อมูลใน datagridview ต้องเขียนยังไงครับ |
|
 |
|
|
 |
 |
|
หลักการ รู้ตำแหน่งปัจจุบัน ในกรณีของคุณ แถวที่เท่าไหร่?/ดอลัมภ์ที่เห่าไหร่?
DataGridViewXXX.CurentRow มันมีให้ใช้
--- ดักจับอีเวนต์เอา อทิเช่น
------ DataGridViewXXX.CurentRow..Cell(69).Text = 1234 ก็ว่ากันไป
ความเข้าใจของคุณกับผม มันเข้าใจตรงกันหรือเปล่า?
--- อธิบายมากไปเกรงว่าจะเข้าใจมากเกินไป ประมาณนั้นฯ
|
 |
 |
 |
 |
Date :
2019-04-17 17:21:20 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO1 หลักการก็ยังเหมือนเดิม รู้ตำแหน่ง
อันนี้เป็น Source Code ที่ฝรั่งเขียน และใช้งานจริงบนแผนที่โลก Google
รู้ Lat/Lng ก็คำนวณระยะทางได้ ผิดพลาด +- 5 เมตร
Code (JavaScript)
/**
* return the distance between 2 latLng in meters
* @param {LatLng} origin
* @param {LatLng} destination
* @returns {Number}
**/
function distanceInMeter(origin, destination) {
var m = Math,
pi = m.PI,
e = pi * origin.lat() / 180,
f = pi * origin.lng() / 180,
g = pi * destination.lat() / 180,
h = pi * destination.lng() / 180,
cos = m.cos,
sin = m.sin;
return 1000 * 6371 * m.acos(m.min(cos(e) * cos(g) * cos(f) * cos(h) + cos(e) * sin(f) * cos(g) * sin(h) + sin(e) * sin(g), 1));
}
|
 |
 |
 |
 |
Date :
2019-04-17 17:24:55 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ Event CellEndEdit ครับ ลองศึกษาดูครับ
|
 |
 |
 |
 |
Date :
2019-04-17 17:26:53 |
By :
DREAMKARIFHA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่มันมีข้อยกเว้น อันนี้คือวิธีคิด/ปฏิบัติได้จริง โดยที่ไม่ต้องอาศัยหลักการ/ความถูกต้อง (ถ้าใช้แบบนี้ จะหาคำตอบไม่ได้)
โจทย์จริงเลยนะ แม่น้ำเจ้าพระยา ทุกฯจุด ทุกฯจุด ทุกฯจุด ล้วนมี Lat/Lng เดียวกัน ทั้งสายน้ำ (a, b, c, d, e, f, ...)
สมมุติว่ามีเรือวิ่งเข้ามาพร้อมฯกัน 100 ลำ ในเวลาเดียวกัน ถ้าเราวาดเส้นทางการเดินเรือแบบ Real time (ทันทีทันใด ถึงตรงไหนรับรู้)
แน่นอนว่า เรือทั้ง 100 ลำ เส้นที่เราวาด มันต้องทับกัน ดูไม่ออกว่าเป็นเรือลำไหน?
หลักการรู้ตำแหน่งที่ถูกต้องจะใช้ไม่ได้กับกรณีนี้
ปล. ลองทำความเข้าใจดูครับ
|
 |
 |
 |
 |
Date :
2019-04-17 17:34:48 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าคุณอยากเล่นกับ DataGridView จริงฯ ลองไล่ดูครับ โลกของ Windows Application DataGridView คงไม่หนีพ้นไปจากนี้

Source Code
Code (VB.NET)
Public Class frmDGVTextButtonvb
Private btnSelector As New Button() With {.TabStop = False, .FlatStyle = FlatStyle.Flat}
'สร้าง Buttnon
Private pCase As Integer
'สำหรับ เก็บส่วนของการเลือก Column
Private x As String
'สำหรับสร้างหี ยังไม่ได้ทำ
Private หี
Private curColIndex As Integer
Private curRowIndex As Integer
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub frmDGVTextButtonvb_Shown(sender As Object, e As EventArgs) Handles Me.Shown
DataGridView1.MultiSelect = False
DataGridView1.Select()
DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.NewRowIndex) 'DataGridView1.Rows(0).Cells(DataGridView1.NewRowIndex)
DataGridView1.CurrentCell.Selected = True
'DataGridView1.BeginEdit(True)
End Sub
Private Sub frmDGVTextButtonvb_Load(sender As Object, e As EventArgs) Handles Me.Load
'DataGridView1.MultiSelect = False
Dim col1 As New DataGridViewTextBoxColumn With {.Name = "Column1", .Width = 100, .DisplayIndex = 0}
Dim col2 As New DataGridViewTextBoxColumn With {.Name = "Column2", .Width = 300, .DisplayIndex = 1}
Dim col3 As New DataGridViewTextBoxColumn With {.Name = "Column3", .Width = 300, .DisplayIndex = 2}
Dim col4 As New DataGridViewTextBoxColumn With {.Name = "Column4", .Width = 120, .DisplayIndex = 3}
'Dim col4 As New DataGridViewComboBoxColumn With {.Name = "cboXXX", .DisplayIndex = 3}
DataGridView1.Columns.AddRange(New DataGridViewColumn() {col1, col2, col3, col4})
'Me.DataGridView1.Rows.Clear()
'Me.DataGridView1.RowTemplate.MinimumHeight = 50
'Dim dgvCol As New Test_Win.TextBoxButtonColumn
'DataGridView1.Columns.Add(dgvCol)
'DataGridView1.Columns.Clear()
' DataGridView1.RowHeadersWidth = 50
CreateButton(btnSelector)
DataGridView1.Controls.Add(btnSelector)
'Fixed ความสูงของแถวแรกไม่เท่ากับแถวอื่นฯ
'DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter
'For Each r In DataGridView1.Rows
' DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(2)
' DataGridView1.BeginEdit(False)
'Next
'DataGridView1.ClearSelection()
'DataGridView1.Select()
'DataGridView1.BeginEdit(True)
'DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(1)
'DataGridView1.CurrentCell.Value = "123"
'DataGridView1.CurrentCell.Selected = True
'ataGridView1.Focus()
' DataGridView1.Columns(0).DisplayIndex = 3
'DataGridView1.ClearSelection()
'DataGridView1.BeginEdit(True)
'For i As Integer = 0 To 100
' DataGridView1.Rows.Add("")
'Next
''Me.DataGridView1.Select()
''DataGridView1.Focus()
'DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
'DataGridView1.CurrentCell = DataGridView1.FirstDisplayedCell
'DataGridView1.BeginEdit(True)
'DataGridView1.ClearSelection()
'If DataGridView1.Rows.Count = 1 AndAlso DataGridView1.Rows(0).IsNewRow Then
' 'DataGridView1.CurrentCell = DataGridView1(0, 0)
' 'DataGridView1.BeginEdit(True)
' 'DataGridView1.Rows(0).Cells(0).Value = "aaa"
' ''DataGridView1.EndEdit()
' ''DataGridView1.UpdateCellValue(0, 0)
' ''DataGridView1.CausesValidation = True
' ''Me.ValidateChildren()
' ''Me.Validate()
' 'DataGridView1.CurrentCell.Selected() = True
' DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
' 'DataGridView1.Rows(0).Cells(0).Value = "aaa"
' DataGridView1.CurrentCell.Value = "asdf"
' DataGridView1.CurrentCell.Selected = True
' DataGridView1.BeginEdit(True)
' 'MsgBox(DataGridView1.CurrentCell.IsInEditMode)
' 'TextBox1.Focus()
' 'DataGridView1.Focus()
'End If
'DataGridView1.CurrentCell.Selected = True
'DataGridView1.BeginEdit(True)
'DataGridView1.FirstDisplayedScrollingRowIndex = 0
''If DataGridView1.CurrentRow.IsNewRow Then
'' MsgBox("Yes")
''End If
'
'DataGridView1.Select()
'DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.NewRowIndex) 'DataGridView1.Rows(0).Cells(DataGridView1.NewRowIndex)
'DataGridView1.CurrentCell.Selected = True
'DataGridView1.BeginEdit(True)
'My.Computer.Keyboard.SendKeys("{BACKSPACE}")
'DataGridView1.MultiSelect = False
'DataGridView1.Select()
'DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.NewRowIndex) 'DataGridView1.Rows(0).Cells(DataGridView1.NewRowIndex)
'DataGridView1.CurrentCell.Selected = True
'DataGridView1.BeginEdit(True)
End Sub
Private Sub SelectorClick(ByVal sender As Object, ByVal e As EventArgs)
Select Case pCase
Case 1
'value from dataGridView1_CellEnter
If True Then
MessageBox.Show("Show Dialog here!!")
'Exit Select
End If
End Select
'DataGridView1.NotifyCurrentCellDirty(False)
'DataGridView1.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
'DataGridView1.CurrentCell = DataGridView1(curRowIndex, 0)
'DataGridView1.CurrentCell.Selected = True
DataGridView1.CurrentCell = DataGridView1(curColIndex, curRowIndex)
DataGridView1.CurrentCell.Selected = True
DataGridView1.BeginEdit(True)
'DataGridView1.CurrentCell.DetachEditingControl()
End Sub
Private Sub CreateButton(ByRef myButton As Button)
Dim dgvHeight As Integer = Me.DataGridView1.RowTemplate.Height
myButton.FlatStyle = FlatStyle.Flat
myButton.FlatAppearance.BorderSize = 0
myButton.Size = New Size(dgvHeight, dgvHeight) 'New Size(30, 30)
myButton.ImageAlign = ContentAlignment.MiddleCenter
myButton.FlatAppearance.MouseDownBackColor = Color.Transparent
myButton.FlatAppearance.MouseOverBackColor = Color.Transparent
myButton.BackColor = Color.Transparent
myButton.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255) '//transparent
'myButton.Image = Properties.resources.search3
myButton.Image = My.Resources.file_new
'myButton.Image = Image.FromFile(CurDir() + "\pic\SearchBc.png")
'myButton.Anchor = AnchorStyles.Right
'myButton.Anchor = AnchorStyles.Top
'กำหนดรูปภาพ
myButton.TabStop = False
'myButton.Parent = DataGridView1
myButton.Hide()
AddHandler myButton.Click, New EventHandler(AddressOf Me.SelectorClick)
'--------------------------------------------
End Sub
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
If DataGridView1.Columns(e.ColumnIndex).Name = "Column1" Then
pCase = 1
Dim Loc As Rectangle = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)
Dim W As Integer = DataGridView1.CurrentCell.Size.Width
Dim H As Integer = DataGridView1.CurrentCell.Size.Height
'btnSelector.Location = New Point(Loc.X - 30 + W, Loc.Y)
Dim x = btnSelector.Height
btnSelector.Location = New Point(Loc.X - btnSelector.Width + W, Loc.Y) '(Loc.X - 30 + width,
btnSelector.Show()
curColIndex = e.ColumnIndex
curRowIndex = e.RowIndex
End If
End Sub
Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
If btnSelector.Focused <> True Then
btnSelector.Hide()
End If
End Sub
Private Sub DataGridView1_ColumnWidthChanged(sender As Object, e As DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged
If e.Column.Index = 0 Then
'If DataGridView1.Columns(e.ColumnIndex).Name = "Column1" Then
'pCase = 1
Dim Loc As Rectangle = DataGridView1.GetCellDisplayRectangle(e.Column.Index, DataGridView1.CurrentCell.RowIndex, False)
Dim width As Integer = DataGridView1.CurrentCell.Size.Width
Dim height As Integer = DataGridView1.CurrentCell.Size.Height
btnSelector.Location = New Point(Loc.X - btnSelector.Width + width, Loc.Y) 'Loc.X - 30 'btnSelector.Width
btnSelector.Show()
'End If
End If
End Sub
Private Sub DataGridView1_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
'If DataGridView1.IsCurrentCellDirty Then
' DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
'End If
End Sub
'Executes when Cell Value on a DataGridView changes
Private Sub DataGridCellValueChanged(sender As DataGridView, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
'check that row isn't -1, i.e. creating datagrid header
If e.RowIndex = -1 Then Exit Sub
'mark as dirty
'IsDirty = True
End Sub
Private Sub DataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
MsgBox(e.Exception.Message)
End Sub
Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
'http://vbcity.com/forums/t/152435.aspx
If DataGridView1.CurrentCell.ColumnIndex = 3 Then
Dim txtedit As TextBox = DirectCast(e.Control, TextBox)
AddHandler txtedit.KeyPress, AddressOf txtEdit_KeyPress
End If
End Sub
Private Sub txtEdit_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If DataGridView1.CurrentCell.ColumnIndex = 3 Then
If ("0123456789.".IndexOf(e.KeyChar) = -1) Then 'If ("0123456789.\b".IndexOf(e.KeyChar) = -1) Then
If e.KeyChar <> Convert.ToChar(Keys.Back) Then
e.Handled = True
End If
End If
End If
End Sub
Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
'If e.KeyCode = Keys.Enter Then
' e.Handled = True
' SendKeys.Send("{TAB}")
'End If
End Sub
End Class
|
 |
 |
 |
 |
Date :
2019-04-18 09:08:35 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากกระทู้ที่ #133458
ผมเล่าเรื่องจริงให้ฟังเลยนะ (ดูเหมือนโกหก แต่จริงฯแล้วไม่ใช่)
ถ้าพวกคุณรู้จักคำว่า "สังเกตุ" จริง/เท็จ หรืออาจจะกล่าวได้ว่า "ความจริงมักซ่อนความจริงเสมอ"
งานตัวอย่างก็จริง (Demo) แต่ความละเอียดอ่อนโปรแกรมมิ่งผมมีมากมากมากเสมอ
ข้างกายของผมมี วิศวะ ทุกสถาบัน มีผมคนเดียวโดดโดดที่จบ มหาลัยรามคำแหง
งานตัวอย่างของผมวิ่งขนานกัน สามภาษา C#/VB/Java และจำนวนข้อมูลวิ่งบนหลักล้านระเบียน
Insert ล้านระเบียน ต้องใช้เวลาแค่ 1 วินาที
ยกแค่ตัวอย่าง VB
Code (VB.NET)
''' <summary>
''' Usage: https://localhost:6969/api/ผัวจ๋า/getAllOilType
''' </summary>
''' <returns>List of (Id, Text, Remark[f1 + f2 + f3 + f4) From id_oiltype (ตาราง ประเภทน้ำมัน)</returns>
<Route("getAllOilType")>
<HttpGet>
Public Function getAllOilType() As IActionResult
Dim strSQL = <Suparuck>
Select oil_type, thai_name, thai_sname, eng_name, eng_sname, oil_group
From id_oiltype
</Suparuck>
Dim results As IList(Of Object) 'IEnumerable(Of Object) '***** สำหรับ Dapper IList(Of Object) <> IList(Of Object)()
Dim fakeList = {New With {.Id = "", .Text = "", .Remark = "", .Remark2 = ""}}.Take(0).ToList()
SexyDatabase.ConfigDatabase(SimpleCRUD.Dialect.MySQL) 'เลือก RDBMMS ตามสะดวก แม้แต่หอยยังชื่นชมแล้วอุทานว่า ผัวจ๋า
Using cn = SexyDatabase.SexyConnection()
results = cn.Query(Of Object)(strSQL.Value)
End Using
For Each r In results
Dim fields = DirectCast(r, IDictionary(Of String, Object)) '***** C# 7 --> row.Cast<IDictionary<string, object>>()
Dim f1 = If(Convert.IsDBNull(fields("oil_type")), "", fields("oil_type").ToString())
Dim f2 = If(Convert.IsDBNull(fields("thai_name")), "", fields("thai_name").ToString())
Dim f3 = If(Convert.IsDBNull(fields("thai_sname")), "", fields("thai_sname").ToString())
Dim f4 = If(Convert.IsDBNull(fields("eng_name")), "", fields("eng_name").ToString())
Dim f5 = If(Convert.IsDBNull(fields("oil_group")), "", fields("oil_group").ToString())
fakeList.Add(New With {.Id = f1, .Text = f2, .Remark = f1 + f2 + f3 + f4, .remark2 = "ผัวจ๋า"})
Next
Return Ok(fakeList.ToList()) 'มันแปลง Property เป็นอักษรตัวเล็กทั้งหมด เช่น id, text, remark, remark2 (ดีเหมือนกันว่ะเฮ้ย)
End Function
|
 |
 |
 |
 |
Date :
2019-04-18 09:48:21 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO7 เอาให้เห็นชัดชัดชัด ให้รู้หีรู้แตดกันไปเลย JAVA
ใช้ทั้ง bean/servlet/etc.. สารพัด อีห่าลากแค่ภาษา C# มันก็ถอกกระดอเหมือนกันแหละ
Code
@Override
public JSONArray getOiltypeList(String orderBy, String searchValue) {
// TODO Auto-generated method stub
JSONArray jsonArray = null;
String sql = " ";
sql += " select oil_type, thai_name, thai_sname, eng_name, eng_sname, oil_group ";
sql += " from id_oiltype ";
if (!searchValue.equals("")) {
sql += " where thai_name like '%"+searchValue+"%' or eng_name like '%"+searchValue+"%' ";
}
if (!orderBy.isEmpty()) {
sql +=orderBy;
} else {
sql += " ORDER BY oil_type ";
}
try {
Statement stmt = con.getInstance().createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
JSONObject formDetailsJson = new JSONObject();
formDetailsJson.put("oil_type", rs.getString("oil_type"));
formDetailsJson.put("thai_name", rs.getString("thai_name"));
formDetailsJson.put("thai_sname", rs.getString("thai_sname"));
formDetailsJson.put("eng_name", rs.getString("eng_name"));
formDetailsJson.put("eng_sname", rs.getString("eng_sname"));
formDetailsJson.put("oil_group", rs.getString("oil_group"));
if (jsonArray == null) {
jsonArray = new JSONArray();
}
jsonArray.add(formDetailsJson);
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonArray;
}
ปล. เจ้าของกระทู้เห็นหรือยังว่า งานโปรแกรมมิ่งมันมีอะไรอีกตั้งมากมายซ่อนอยู่
|
 |
 |
 |
 |
Date :
2019-04-18 10:19:52 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|