在varialbe中存储datagridview名称 [英] Storing datagridview name in a varialbe

查看:75
本文介绍了在varialbe中存储datagridview名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在处理用户权限。我想使用以下代码加载检查的网格项。



 Dim l As Integer = 0,vrGridName As New DataGridView,vrGridItemIndex As Integer 
taSaveTemplates.Connection.ConnectionString + =; password =& vrSAPWD
Me.taSaveTemplates.Fill(Me.DsSaveTemplates.tblTemplates,lstTemplateID.Text)
'根据保存的数据加载网格
Do DsSaveTemplates.tblTemplates.Rows.Count> l
vrGridName.Name = DsSaveTemplates.tblTemplates.Rows(l).Item(GridName)
vrGridItemIndex = DsSaveTemplates.tblTemplates.Rows(l).Item(GridItemIndex)
vrGridName .Item(0,vrGridItemIndex).Value = True
l = l + 1
循环





vrGridName存储从DB中选择的网格名称,vrGridItemIndex存储需要检查的项目。



问题是,当我运行代码时,它表示索引是我们的范围。

我已经检查过,vrGridName不存储网格的名称但存储

System.windows.datagridview



请指教。

谢谢

解决方案

嗯......这里有很多错误,但是让我们专注于基础...

这种方法不起作用。



DataGridView的Name属性是一个字符串,而已。它不会传输任何其他信息,它肯定不会使DataGridView引用其中包含数据的现有版本 - 所以当您尝试访问项目时,没有任何信息,因为您访问的DataGridView不是与现有的一个完整的数据相同,它只有相同的Name属性。



现在,我不确定你到底想要做什么,但是我怀疑你试图通过以下方式将整个DataGridView存储到数据库中:

  Dim  sql 作为 字符串 =   INSERT INTO MyTable(MyColumn)VALUES(' + myDataGridView +  ') 

哪个赢得了工作,甚至是轻微的工作,因为所有它都将类的名称存储到数据库中:

System.Windows.DataGridView

不是内容。



您需要坐下来重新考虑整个项目:因为我怀疑所有东西都需要重新设计,从数据库开始!


可以通过访问它的ID属性从你的vrGridName变量中检索GridViewName。



  Dim  sGridName 作为 字符串 = vrGridName.ID 





希望它有所帮助。


Hi,
I am working on user rights. I want to load the grid items checked using following code.

Dim l As Integer = 0, vrGridName As New DataGridView, vrGridItemIndex As Integer
       taSaveTemplates.Connection.ConnectionString += ";password=" & vrSAPWD
       Me.taSaveTemplates.Fill(Me.DsSaveTemplates.tblTemplates, lstTemplateID.Text)
       'Load Grids according to data saved
       Do While DsSaveTemplates.tblTemplates.Rows.Count > l
           vrGridName.Name = DsSaveTemplates.tblTemplates.Rows(l).Item("GridName")
           vrGridItemIndex = DsSaveTemplates.tblTemplates.Rows(l).Item("GridItemIndex")
           vrGridName.Item(0, vrGridItemIndex).Value = True
           l = l + 1
       Loop



vrGridName stores the name of grid selected from DB and vrGridItemIndex stores the item that needs to be checked.

The problem is, when I run the code, it says Index is our of range.
I have checked, the vrGridName does not store the name of grid but stores
System.windows.datagridview

Please advise.
Thanks

解决方案

Well...there are a huge number of things wrong here, but lets concentrate on the fundamentals...
This approach won't work.

The Name property of a DataGridView is a string, nothing more. It does not transfer any other information, and it certainly doesn't make a DataGridView refer to an existing version with data in it - so when you try to access items, there aren't any, because the DataGridView you are accessing is not the same one as the existing one full of data, it just has the same Name property.

Now, I'm not sure exactly what you are trying to do, but I suspect that you are trying to store a whole DataGridView into your database by doing something along the lines of:

Dim sql As String = "INSERT INTO MyTable (MyColumn) VALUES ('" + myDataGridView + "')"

Which won;t work, even slightly, because all it does it store the name of the class into the database:

System.Windows.DataGridView

not the content.

You need to sit down and rethink the whole of this project: because I suspect that everything need to be redesigned, from the database on up!


The GridViewName can be retrieved from your vrGridName variable by access it's ID property.

Dim sGridName As String = vrGridName.ID



Hope it helps.


这篇关于在varialbe中存储datagridview名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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