[英]How to add value to a cell in a datagridview using a query?
I have a bound datagridview that has an unbound column. 我有一个绑定的datagridview有一个未绑定的列。 I'm using cellformatting to look up the Employee ID in the same row to return the employee's name from a different datatable.
我正在使用单元格格式在同一行中查找“员工ID”,以从其他数据表返回员工的姓名。
I get everything working fine, the only problem is that i can only get one part of the name to show either the first name, middel, last, but not all together. 我一切正常,唯一的问题是我只能得到名字的一部分来显示名字,middel,last,但不能一起显示。
This is the code i have so far (I'm very new to coding, all that i have so far has been from forums or research only, so please comment your answer): 这是我到目前为止所拥有的代码(我对编码非常陌生,到目前为止我所拥有的一切都仅来自论坛或研究,因此请评论您的答案):
If dgvr.Cells(0).Value IsNot Nothing AndAlso dgvr.Cells(0).Value IsNot DBNull.Value Then
Dim empID As Integer = CInt(dgvr.Cells(0).Value)
Dim qry = From dr As PersonalObraDataSet.PersonalObRow In _PersonalObraDataSet.PersonalOb _
Where (dr.cdTrabajador = empID)
'If qry.Count > 0 Then
DataGridView1.Rows(e.RowIndex).Cells(1).Value = qry.First.Apellido1
'DataGridView1.Rows(e.RowIndex).Cells(2).Value = qry.First.Nombre2
End If
'End If
You can combine strings with & operator. 您可以使用&运算符组合字符串。 It would be something like
就像
DataGridView1.Rows(e.RowIndex).Cells(1).Value = qry.First.Nombre2 & " " & qry.First.Apellido1 & " " & qry.First.SegundoNombre3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.