|
-
December 12th, 2008, 11:40 AM
#1
Data Grid
Hello,
I am using VB2008
To keep it plain and simple i have a datagrid in my application that has an unknown amount of rows and set amount of columns (4 of them). This datagrid i have created is for a simple inventory manager to ensure my stock is up to date. I have everything working just they way i want accept i want to be able to change the color of a number from black to red if it goes below a set number.
My columns are Part Number, Part, Min Qty, Quantity. Each part has a different set minimum quantity so i need something that will compare Min Qty and Quantity column. As an example: Row 6 has a minimum quantity of 50 entered into the Min Qty cell for that row and the Quantity cell has 75, So that means i have more then my minimum quantity. So the numbers in my Quantity column should stay black. Now lets say in row 5 the Min quantity is set to 30 and The quantity column has a number of 25 in it. I want that number to show up as red, meaning that we have fallen below a minimum quantity. I hope i have given enough information and if i havent please let me know. I have done some searching around the www but i havent found anything that i am looking for. Thank you in advance for any help.
-
December 12th, 2008, 12:09 PM
#2
Re: Data Grid
Think I know exactly what you mean...
Have a look at this:
You need a datagridview (call it DataGridView1) with 2 columns (1st one is min qty, 2nd is qty) and a button (Button1).
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Rows.Add(2)
DataGridView1.Rows(0).Cells(0).Value = 70
DataGridView1.Rows(0).Cells(1).Value = 75
DataGridView1.Rows(1).Cells(0).Value = 30
DataGridView1.Rows(1).Cells(1).Value = 25
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(0).Value > row.Cells(1).Value Then
For Each cell As DataGridViewCell In row.Cells
cell.Style.ForeColor = Color.Red
Next
End If
Next
End Sub
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010
-
December 12th, 2008, 01:10 PM
#3
Re: Data Grid
Thank you for the code.
That seems to work nicely but its not quite what i am looking for. One problem that i found is once you have clicked the button and the numbers changed to red, if you change the quantity to a greater number than the minimum quantity and click the button again the numbers will stay red.
Here is a little more information that could be of some help. I am drawing all my Data from Microsoft Access and as changes are made in the data grid i have a save button to update my database.
What i am looking for is probably a little more work but will make things easier when updating the data base. Also in your code that you supplied me both numbers in the row turned red, i think i only want the quantity column to turn red, and possibly bold so it really stands out. If possible i would like to avoid having to click a button to perform this action just to keep the program plain and simple for other users. Thank you in advance for any help
-
December 12th, 2008, 11:50 PM
#4
Re: Data Grid
You need an event for OnChanged. Then, you could check validate in that code
-
December 13th, 2008, 12:02 AM
#5
Re: Data Grid
And a simple else clause to set the color back if it is valid.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 15th, 2008, 08:18 AM
#6
Re: Data Grid
Yes thats sounds something along the line i would like to use. Could someone please supply me with some code so i can test it out. Any help is very much appreciated. Thank you
-
December 15th, 2008, 06:47 PM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|