Click to See Complete Forum and Search --> : Data Grid


YMCORP
December 12th, 2008, 10:40 AM
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.

HairyMonkeyMan
December 12th, 2008, 11:09 AM
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).

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

YMCORP
December 12th, 2008, 12:10 PM
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

dglienna
December 12th, 2008, 10:50 PM
You need an event for OnChanged. Then, you could check validate in that code

TheCPUWizard
December 12th, 2008, 11:02 PM
And a simple else clause to set the color back if it is valid. ;)

YMCORP
December 15th, 2008, 07:18 AM
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

dglienna
December 15th, 2008, 05:47 PM
Ever hear of GOOGLE?

http://www.vbdotnetheaven.com/UploadFile/LivMic/OnChanged_UserControl11282006225432PM/OnChanged_UserControl.aspx