如何使用vb.net在数据表中查找行索引? [英] How do i Find row index in datatable using vb.net?

查看:507
本文介绍了如何使用vb.net在数据表中查找行索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

在某些情况下,我正在使用NewRow函数在DataTable中添加新行.这导致调用数据表的另一个事件"OnColumnChanged".我想获取最近添加的行的RowIndex.

当我尝试使用代码获取新添加的行的行索引时:

Hello,

On some event, I am adding a new row in DataTable using NewRow function. which results in calling another event of DataTable "OnColumnChanged". I want to get a RowIndex of recently added row.

When I try to obtain row index of newly added row using code :

lDataRow = e.Row
lRowNumber = ldatatable.Rows.IndexOf(lDataRow)




我得到lRowNumber即RowIndex为"-1".而不是实际索引.

我需要下一个功能TableName,ColumnName,RowIndex,ProposedValue参数.

在这种情况下,如何获取当前的RowIndex,或者反之.

在此先感谢.




I am getting lRowNumber i.e RowIndex as "-1". Instead of actual index.

I require, TableName, ColumnName, RowIndex, ProposedValue parameters for my next functioning.

How can I Obtain current RowIndex in this event, OR whats the other way around.

Thanks in advance.

推荐答案

NewRow()只是使用表的架构创建一行.不会将行添加到DataTable&在将新行添加到表之前,您无法获取索引.这是一个例子
(假设dt是DataTable)

The NewRow() simply creates a row with the schema of the table. It does not add the row to the DataTable & you cannot get the index until you add the new row to the table. Here''s an example
(assuming dt is the DataTable)

Dim row As DataRow = dt.NewRow()
' IndexOf() will return -1 if called here
dt.Rows.Add(row)
' get the index now
MsgBox(dt.Rows.IndexOf(row))


感谢strogg.你是绝对正确的.

其实我的问题是我在新创建的行中动态设置了诸如SerialNumber等数据,该行被更新到数据源中,然后转到客户端,新行反映在datagrid中.

我有解决这个问题的想法.我将使用datatable的RowChanged事件获取新添加的行的索引,然后将其用于进一步的过程.

我还没有实现这个想法.希望这个想法对我有用.
Thanks strogg. You are absolutely correct.

Actually my problem is I am dynamically setting the data like SerialNumber etc in newly created row which gets updated into datasource and then goes to the client side where this new row is reflected in datagrid.

I have an idea about solving this problem. I''ll be using RowChanged event of datatable to get index of newly added row and then use that for further procedure.

I am yet to implement this idea though. Hope this idea work for me.


这篇关于如何使用vb.net在数据表中查找行索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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