|
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.
|
|
|
|
|
As useful as this was it still doesn't let me draw outside the bounds of my control, it just cuts it off.
|
|
|
|
|
I once tried ControlPaint.DrawReversibleLine and dropped it since it ignored
all windowing, so when applied to a window that was partly covered by something else
it was painting over that something else, what I did not want at the time.
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 i can't get it to paint outside my control, then again i am caling it from within my contro, don't know if this should make a difference, but i certainly can't draw anywhere on the screen.
|
|
|
|
|
There seem to be two kinds of drawing methods in ControlPaint:
- the ones working on the screen, using screen coordinates, ignoring all windows, just
painting everywhere;
- the ones needing a Graphics; now a Graphics always has clipping built-in, that's one of
its features (did you ever care about a DrawString exceeding the width of a Control?).
As another reply already told you, you (theoretically) cannot make a Control's OnPaint
paint outside the Control, i.e. you must set the Control's Size large enough so it contains
all the areas where you want it to paint something (that's how non-rectangular Forms
basically work, as far as I can tell from reading some articles, I am not really in to this).
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
|
|
|
|