Datagridviewrow使用列名而不是索引 [英] Datagridviewrow using column name instead of index

查看:117
本文介绍了Datagridviewrow使用列名而不是索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我在下面使用的代码

Here is the code I'm using below

Dim lname As New DataGridViewColumn

lname.Name = "LastName"
lname.DataPropertyName = "LastName"
DataGridView1.Columns.Add(lname)

Dim itrow = New DataGridViewRow    
itrow.CreateCells(DataGridView1)                
itrow.Cells(0).Value = empcoll.Item(i).LastName <<works
itrow.Cells("LastName").Value = empcoll.Item(i).LastName <<error column name can't be found

我无法使用 datagridviewrow.cells(列名)。任何人都可以启发或帮助我吗?

I'm having trouble with using datagridviewrow.cells("column name"). Can anyone enlighten or help me?

推荐答案

尝试这个(稍微改变一些东西来尝试代码,如果它的工作原理) p>

Try this (I slightly change something to try the code if it works):

  Dim lname As New DataGridViewColumn
  lname.Name = "LastName"
  lname.DataPropertyName = "LastName"
  lname.CellTemplate = New DataGridViewTextBoxCell 'I had to add this to my code

  DataGridView1.Columns.Add(lname)

  Dim itrow As New DataGridViewRow
  itrow = DataGridView1.Rows(DataGridView1.Rows.Add())
  itrow.Cells("LastName").Value = "Give here your Value"

这篇关于Datagridviewrow使用列名而不是索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆