|
Doesn't sound like your talking about events. you only have 1 event. the click event. inside that event you need to call 3 functions. each function should be a boolean so that you know whether or not to continue.
Sub Button_click(sender as object, e as system.eventargs) handler button.click
If bPrintFirstReport Then
If bPrintSecondReport Then
If bPrintThirdReport Then
'
else
'report error
End If
Else
'report error
End If
Else
'report error
End If
end sub
|
|
|
|
|
VB6 Property set with two parameters won't port to VB.Net
I'm trying to port a VB6 class called VBXML to VB.Net in such a way to also minimise changes to client code using the class.
In VB6 the class has a property called FieldValue that is defined with 2 parameters:
Public Property Get FieldValue(strXPath As String) As Variant<br />
<br />
CurrentField = strXPath<br />
FieldValue = CurrentFieldValue<br />
<br />
End Property<br />
<br />
Public Property Let FieldValue(strXPath As String, pvarNewValue As Variant)<br />
<br />
CurrentField = strXPath<br />
CurrentFieldValue = pvarNewValue<br />
<br />
End Property
Now without going into the innards this Property Let allows client code to be written like this:
Dim obj As VBXML<br />
<br />
Set obj = New VBXML<br />
obj.FieldValue("ID") = 10<br />
obj.FieldValue("Name") = "Gordon Brown"<br />
obj.FieldValue("Address") = "10 Downing Street"
This client code in VB6 generates a call to the property let with the string argument strXPath being passed as "ID" or "Name" or "Address" in the 3 examples above and with the variant pvarNewValue being passed as 10 or "Gordon Brown" or "10 Downing Street".
This is very convenient and intuitive syntax a bit like we used record sets:
rs.Fields("ID") = 10<br />
rs.Fields("Name") = "Gordon Brown"<br />
rs.Fields("Address") = "10 Downing Street"
It seams that equivalent VB.Net Property Let declarations are only ever allowed to have 1 parameter otherwise you receive an error: 'Set' method cannot have more than one parameter
So the question is how do I rewrite the class property so that client code will be able to be of this form and with minimal changes? The client code is also being ported to VB.Net by the way.
|
|
|
|
|
Ex:
Test("bbbb") = "hello"
Public WriteOnly Property Test(ByVal o As Object) As String
Set(ByVal value As String)
MsgBox(o)
Msgbox(value)
End Set
End Property
|
|
|
|
|
I did wonder what the relationship was between the argument in the declaration of the property itself and the argument in the declaration of the Set of the property in VB.Net. Now I know! Thanks for the very quick answer.
|
|
|
|
|
A list of numbers is input in a list box, say (4.8,6.9,8.0,3.2). The sum of these numbers are displayed in a textbox using:
For Index As Integer = 0 To lstbox1.Items.Count - 1
Total += CDbl(lstbox1.Items(Index))
Next Index
When one of those numbers are removed from the listbox, the total is accumulated , that is the new total is added to the old one. How can I correct this so that the total given is always, the total of the numbers in the listbox.
|
|
|
|
|
try an occasional Total=0
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I need help with updating an access database table(access database is included in my project). my data comes from an xml that will periodically be updated and displayed on a DataGrid field. I manage to display the data onto datagrid and now I want to copy the displayed data into an access database table. Does anyone knows how to do that?
Thanks for your help
Maria
|
|
|
|
|
1. Iterate through the rows in your DataGrid control.
2. For each row, execute an INSERT INTO...VALUES DML query that inserts a row of data into a table in your Access database. This query could be constructed dynamically as a string or it could be a parametetized query stored in the Access database.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks Paul,
This is what I have done so far but it doesnt work:
##################################################################
Dim newRows as DataRow = DatabaseDataSet.Tables("Table1").NewRow()
Dim dr As DataRow
For Each dr In Me.DataGrid1.Rows
newRows = dr
DatabaseDataSet.Tables("Table1").Rows.Add(newRows)
Next
##################################################################
Please help!
Maria
|
|
|
|
|
What do you mean 'it doesn't work'? What do you expect it to do? Do you get an error? You need to be more specific.
All your code appears to do is add rows to a Table in a DataSet. Where is your code to connect and add the data to your Access database? I suggested a way of doing this in my previous post.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Have a look at this article[^]. It explains how to use data adapter and command builder classes to update an underlying data source when data in a datatable is modified. The code in the article is written for use with SQL Server, but if you change the System.Data.SqlClient classes used to their equivalents in the System.Data.OleDb namespace then you can achieve the same result with an MS Access database.
Any more questions, just ask.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
mparlitu wrote: Dim row As DataRow
This declaration is incorrect. row should be defined as a type of DataGridViewRow .
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Paul,
I have changed the type to DataGridViewRow and now I get the error saying:
Error 1 Class 'System.Windows.Forms.DataGridViewRow' cannot be indexed because it has no default property.
####################################
For Each row In DataGridView1.Rows
dt.Rows.Add(row)
row("Label") = DataGridView1.Columns("Label")
row("Data") = DataGridView1.Columns("Value")
Next
####################################
If I take out this two lines...
row("Label") = DataGridView1.Columns(0)
row("Data") = DataGridView1.Columns(1)
... I get the database updated with: DataGridViewRow { Index=1 } up to DataGridViewRow { Index=31 } one for each record found in DataGrid; on the first column of the table.
Do I need to index each cell in DataGrid?
Thank you,
Maria
|
|
|
|
|
You should really read the documentation[^] before posting questions like this. The error message explains what the problem is and consulting the documentation would have made it clear what you needed to change.
The DataGridViewRow class doesn't have a default property. To get/set the value of a particular cell in a row, you need to reference its Cells collection. Something like this:
row.Cells("Label").Value = DataGridView1.Columns("Label")
Hope this helps.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks Paul,
It is working now!!! I have all my data from DataGrid moved to Access.
Thanks again, I really appreciate your help!
x x x
Maria
|
|
|
|
|
Great! Happy to help
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I have a custom control and am painting a custom border, how do i paint this outside of the bounds of the control from within the control itself. It's just a custom panel so its a straight rectangle.
|
|
|
|
|
It's possible to do, but you shouldn't do that. The entire control is supposed to go inside the bounds of the control, including any border.
The Graphics object that you get in the Paint event is clipped to the bounds of the control or the part of the control that needs redrawing. If you draw outside this clipping, you risk drawing on top of other windows.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
yes but because the control contains other controls the border appears under them, or how do i draw over the top of all controls in the control remaining inside the bounds.
|
|
|
|
|
Override the OnPaint method so that you can do your drawing after you call the OnPaint method of the base class.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Did that. Still not working. I can't seem to just draw a rectangle straight over the top of everything in my control, even if i paint it after on paint. How do i make things i paint out of the control's bounds visible?
|
|
|
|
|
Hi, have a look at the ControlPaint class, it allows you to paint anywhere on the screen!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thankyou this was very useful. Now...you wouldn't happen to know the best way to change the client area would you?.
I need it to behave similar to a form in the sense that we can't place a control on or under the title bar but we can put it anywhere else on the form. I need to just redefine the client area location and width. Howe can i achieve this?
|
|
|
|
|
Hi,
The ANZAC wrote: I need to just redefine the client area location and width.
Well you can set a new ClientSize, but I guess it just resizes the entire Form.
I have never tried to create a different Form layout. If I were to need such thing
I would try this:
- create MyForm class inheriting from Form;
- probably select a very simple BorderStyle (maybe None);
- organize the painting of the non-client area (border, title bar, close box, whatever);
- override some properties such as ClientSize, ClientRectangle, ... (and maybe a whole lot
more);
- and hope the majority of properties and methods can remain unchanged.
I do not plan to try this on XP. And I hope I will never need to do it on Vista,
although I am pretty sure I will not like transparant title bars...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
well it's a panel not a form, problem is the clientsize is readonly and not overridable (i don't think) only overloadable. I wouldn't need to do this if i could just figure out how to paint outside my controls bounds.
|
|
|
|