What I have is three forms. Form one with buttons 1, 2 and 3; and forms 2 and 3 with datagrids.
Button 1 populates arrays a(i,j) and b(i,j) with values.
Button 2 creates a datatable containing the a(i,j) array then adds that table to a dataset
which is in turn bound to a datagrid in an instance of form 2 called matrixa.
Button 3 creates a datatable containing the b(i,j) array then adds that table to a dataset
which is in turn bound to a datagrid in an instance of form 3 called matrixb.
When I start the debugger and click in sequence buttons 1 2 and 3, everything goes exactly as planned. If,
however I then press button 2 again I get an error: "Column 'Column1" does not belong to matrixa"
I have discovered that the problem dissapears if I have button 2 call populatea() twice.
What's going on here?
:
#Region "Public dimension statements"
Public a_m As Integer = 5
Public a_n As Integer = 5
Public a(6, 6) As Double
Dim matrix_A As New form2
Public b_m As Integer = 5
Public b_n As Integer = 5
Public b(6, 6) As Double
Dim matrix_B As New Form3
#End Region
#Region "populate arrays a and b"
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
Dim i As Integer
Dim j As Integer
For i = 1 To 5
For j = 1 To 5
a(i, j) = i + j
b(i, j) = i * j
Next
Next
End Sub
#End Region
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
populateA()
End Sub
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click
populateB()
End Sub
#Region "This is the 'A' data grid populate section"
Private Sub populateA()
Dim dta As New DataTable("matr ixa")
Dim dca(a_n + 1) As DataColumn
Dim dra(a_m + 1) As DataRow
Dim dataset1 As New DataSet
'loop in columns
Dim i As Integer = 0
Dim j As Integer = 0
For j = 0 To a_n - 1
dca(j) = New DataColumn("")
dca(j).DataType = System.Type.Get Type("System.Si ngle")
dta.Columns.Add (dca(j))
Next
'create rows
For i = 0 To a_m - 1
dra(i) = dta.NewRow
For j = 0 To a_n - 1
dra(i)(j) = a(i + 1, j + 1)
Next j
Next i
'add rows to table
For i = 0 To a_m - 1
dta.Rows.Add(dr a(i))
Next
'create instance of dataset
dataset1 = New DataSet
'use add method to enter table into dataset
dataset1.Tables .Add(dta)
'bind the dataset to the grid
matrix_A.Text = "MATRIX A"
matrix_A.MdiPar ent = Me
matrix_A.DataGr id1.SetDataBind ing(dataset1, "matrixa")
matrix_A.Show()
dta = Nothing
dataset1 = Nothing
System.GC.Colle ct()
End Sub
#End Region
#Region "This is the 'B' data grid populate section"
Private Sub populateB()
Dim dtb As New DataTable("matr ixb")
Dim dcb(b_n + 1) As DataColumn
Dim drb(b_m + 1) As DataRow
Dim dataset2 As New DataSet
'loop in columns
Dim i As Integer
Dim j As Integer
For j = 0 To b_n - 1
dcb(j) = New DataColumn
dcb(j).DataType = System.Type.Get Type("System.Si ngle")
dtb.Columns.Add (dcb(j))
Next
'create rows
For i = 0 To b_m - 1
drb(i) = dtb.NewRow
For j = 0 To b_n - 1
drb(i)(j) = b(i + 1, j + 1)
Next j
Next i
'add rows to table
For i = 0 To b_m - 1
dtb.Rows.Add(dr b(i))
Next
'create instance of dataset
dataset2 = New DataSet
'use add method to enter table into dataset
dataset2.Tables .Add(dtb)
'bind the dataset to the grid
matrix_B.Text = "MATRIX B"
matrix_B.MdiPar ent = Me
matrix_B.DataGr id2.SetDataBind ing(dataset2, "matrixb")
matrix_B.Show()
dtb = Nothing
dataset2 = Nothing
System.GC.Colle ct()
End Sub
#End Region
--
mark 8 1879
Mark,
I do not see the reason, however when you send a problem to the newsgroup
than it has to be I think for this problem like this, however make it
readable for us.
When you say you do something with button 2 set than the procedure in
button2 and not in a Sub.
As well tell in what line the problem occurs, I assume in this one however
when that stays a question helping is much more difficult. dta.Columns.Add (dca(j))
(Do you want to keep that array structure by the way, or are you using the
logic from the dataset, when you take the last as would be normal I would
not create those datacolumns/rows in a matrix before).
You are now creating ttree reference systems (datagrid, datatable, array of
items).
Cor
Mark,
I do not see the reason, however when you send a problem to the newsgroup
than it has to be I think for this problem like this, however make it
readable for us.
When you say you do something with button 2 set than the procedure in
button2 and not in a Sub.
As well tell in what line the problem occurs, I assume in this one however
when that stays a question helping is much more difficult. dta.Columns.Add (dca(j))
(Do you want to keep that array structure by the way, or are you using the
logic from the dataset, when you take the last as would be normal I would
not create those datacolumns/rows in a matrix before).
You are now creating ttree reference systems (datagrid, datatable, array of
items).
Cor
The matrix is funamental. The datagrid is for show. The datatable is a necessary go between. the line number is not identified.
You understand language barriers and I hope you can be more flexable with code presentation
You responce was appreciated.
mark
"Cor Ligthert" wrote: Mark,
I do not see the reason, however when you send a problem to the newsgroup than it has to be I think for this problem like this, however make it readable for us.
When you say you do something with button 2 set than the procedure in button2 and not in a Sub.
As well tell in what line the problem occurs, I assume in this one however when that stays a question helping is much more difficult.
dta.Columns.Add (dca(j))
(Do you want to keep that array structure by the way, or are you using the logic from the dataset, when you take the last as would be normal I would not create those datacolumns/rows in a matrix before).
You are now creating ttree reference systems (datagrid, datatable, array of items).
Cor
Mark,
Where did the error occurs, you did not write that?
Cor
--
mark
"Cor Ligthert" wrote: Mark,
Where did the error occurs, you did not write that?
Cor
I am not sure I understand your question.
When I start the debugger and click in sequence buttons 1 2 and 3, everything goes exactly as planned. If, however I then press button 2 again I get an error: "Column 'Column1" does not belong to matrixa"
I believe this error I am seeing is a bug in VB.net - a serious one. It seems tedious I know, but could you try reporoducing the error by pasting my code into your developer. Use the separate populatea() function version I provided. This way you will be able to see how calling the function twice in a row eliminates the effect.
Mark,
I assume that this is what you want to do
matrix_A.MdiPar ent = Me
matrix_A.DataGr id1.DataSource = Nothing
matrix_A.DataGr id1.DataSource = dataset1.Tables ("matrixa")
matrix_A.Show()
And delete than those 3 instructions after that.
When you would want to clear the dataset that is
dataset.clear
calling the GC cost only extra processing time.
The Datagrid holds no data only references to it in the datasource, so when
you clear the dataset that one is empty.
(That databinding from the datagrid is the same by the way, however this is
more done).
I hope this helps?
Cor
Cor;
Yes your techn ique works well.
Is it possible to bind the datagrid directly to the array - bypassing the datatable altogether?
--
mark
"Cor Ligthert" wrote: Mark,
I assume that this is what you want to do matrix_A.MdiPar ent = Me matrix_A.DataGr id1.DataSource = Nothing matrix_A.DataGr id1.DataSource = dataset1.Tables ("matrixa") matrix_A.Show()
And delete than those 3 instructions after that. When you would want to clear the dataset that is dataset.clear calling the GC cost only extra processing time.
The Datagrid holds no data only references to it in the datasource, so when you clear the dataset that one is empty.
(That databinding from the datagrid is the same by the way, however this is more done).
I hope this helps?
Cor
Mark,
When I have understand this documentation well, it should go, however I
never tried that really because of what I write after the links. http://msdn.microsoft.com/library/de...ourceTopic.asp http://msdn.microsoft.com/library/de...classtopic.asp
Why not use the datatable as your datasource it is much more easier to
reference to than an array
dt.rows(0)(0) is the first item
dt.(rows(dt.row s.count-1)(dt.rows.item list.count-1) is the last one.
There are a lot of features in a datatable you do not have in an array.
(And before I forget I think it is better to set allowsort to false in your
datagrid).
I hope this helps?
Cor Cor;
Yes your techn ique works well.
Is it possible to bind the datagrid directly to the array - bypassing the
datatable altogether? -- mark
"Cor Ligthert" wrote:
Mark,
I assume that this is what you want to do matrix_A.MdiPar ent = Me matrix_A.DataGr id1.DataSource = Nothing matrix_A.DataGr id1.DataSource = dataset1.Tables ("matrixa") matrix_A.Show()
And delete than those 3 instructions after that. When you would want to clear the dataset that is dataset.clear calling the GC cost only extra processing time.
The Datagrid holds no data only references to it in the datasource, so
when you clear the dataset that one is empty.
(That databinding from the datagrid is the same by the way, however this
is more done).
I hope this helps?
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeff |
last post by:
IDE: VS 2003 :NET
OS: XP Pro
My app have a form with a tab-control on it. The tab-control have 2
tabpages. One of the tabpages displays a datagrid, and the other tabpage
displays details (order date, name, address etc) about the selected row in
the datagrid...
My problem is when I enter a new record in the details tabpage (saves data
to database), and go back to the datagrid. Only the data from the PM-table
|
by: Alpha |
last post by:
I have several textboxes that I need to chang the text when the selection row
is changed in a datagrid. I have the following code. This textbox displayes
the initial selection but when I click on different rows in the datagrid, the
textbox content doesn't change to reflect the change. How can I address
this?
Also, If the user change the text in the textbox then how do I refesh the
display in the datagrid to reflect the changes?
...
|
by: vinayak |
last post by:
Hi
I am displaying data in Datagrid in ASP.NET with
Edit/Update functionality for each row. On the same page I
have 2 Button controls which submits the request to
server. These button controls are Web Control & not HTML
control. One of these buttons whose title is Delete is
added on the aspx page in design view & also I double
clicked on this button in design view to get the onclick
code for this button in the code behind page. & for...
|
by: A_PK |
last post by:
I have problem databinding the DataGrid with DataView/DataSet after the
filter...
I create the following proceudre in order for user to filter as many as they
want, but the following code is only allow user to filter the first time,
when they tried the second time, the speficied cast error message will
prompt one....
I create a mydataset1 first, and the mydataset1 data source was getting from
DataGrid.DataSource.
|
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= |
last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor
information and the details loads the documents for that vendor in a
datagrid. Everything is working fine until I click in the child datagrid and
then go to the combobox and choose another vendor. When the new vendor is
loaded nothing shows in the datagrid but the itemsource shows the info is
there. Know if I click on the child cell and then click back on the...
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |