2 Attachment(s)
Find And Get Data In Datagridview With Condition / Statement
Hello Guys!
I have problem with my project, I dont know how to impelementation Search and Get data in datagrid view with statement, I mean with WHERE.
This is the ilustration :
Let's Say The Table Below A Datagridview, with 5 Columns and 5 Rows.
Attachment 108899
The example of my problem, in S1 :
1. Check Ranking A = Ranking B?
2. Find Ranking B that have Value = Ranking A!
3. Take Nilai B in the Row-2!
4. Find the difference between Nilai B in S1 and S2
Quote:
[0.9 and 0.6 = 0.3]
5. Add new Columns and Put 0.3 right there.
And The Result Will be like this :
Attachment 108901
I dont Understand about Step 2 and Step 3, Somebody please Help Me! I’m confuse because there is no WHERE in VB.Net to make Condition! :wave::wave:
Re: Find And Get Data In Datagridview With Condition / Statement
I think you may be able to do this by adding a new column to the underlying data table and settings its expression property correctly.
DataColumn.Expression Property
Take a look at the IIF function; about 3/4 of the way down on that page.
The reason I say I think is because I don't quite understand what you want. In particular
Quote:
2. Find Ranking B that have Value = Ranking A!
Row-2 [S2]
Can you elaborate?
Re: Find And Get Data In Datagridview With Condition / Statement
Thanks For Replay! :)
I use S1 for example to explain my problem!
S1 Have Ranking A = 1
S1 Have Ranking B = 4
S1 Have Nilai A = 80
S1 Have Nilai B = 0.9
First : Check Did Ranking A = Ranking B [1=4] --> NO
Okay..
Then : Find Data In Ranking B Coulmn Where The Value = Ranking A in Row S1 ---> So Find Data In Ranking B Column Where The Value = 1
The answer is : A value of 1 is on Second Row.
The Second Row Is S2
S2 Have Ranking A = 3
S2 Have Ranking B = 1
S2 Have Nilai A = 70
S2 Have Nilai B = 0.8
Then : Find Difference between Nilai B Second Row and Nilai B in First Row ->> 0.9 - 0.8 = 0.1
Do you understand what i Mean?
Re: Find And Get Data In Datagridview With Condition / Statement
Please Help Me Broo!!
I realy Don't Understand, This Is My Final Problem! Testing Phase On My research!!
Re: Find And Get Data In Datagridview With Condition / Statement
Where is this data coming from? Is there an underlying datatable or are these values added directly from some process?
Re: Find And Get Data In Datagridview With Condition / Statement
Did you look at the DataColumn.Expression property? Will that work for you? Have you written any code for this? If so what does it look like? Does it do what you would expect? Do you have the data that is in the datagridview? Is it in a table or do you populate the grid manually? You are the one that know what needs to happen to the data; you have it fairly well laid out above in pseudo code, now you just need to code it. I hope you are not expecting some to do that for you, because that would defeat the reason I visit this site. Give it a go and if you get stuck, post relevant code and good questions.
1 Attachment(s)
Re: Find And Get Data In Datagridview With Condition / Statement
I'm using MySQL to acces the data.. That picture in first post just example, this is the real my datagridview :
Attachment 108903
I have been try to solve this problem, but i dont understand:
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
dgv.Columns.Add("Diff", "Diff")
For i As Integer = 0 To dgv.Rows.Count - 1
For j As Integer = 0 To dgv.Columns.Count - 1
If dgv.Rows(i).Cells(1).Value <> dgv.Rows(i).Cells(2).Value Then
WHAT NEXT?
End If
Next
Next
End Sub
Re: Find And Get Data In Datagridview With Condition / Statement
Well, help has been offered but you have refused to heed it so far. If you're getting the data from the database then you should be binding it to the grid, in which case you should not be touching the grid at all for what you want. You should be working exclusively with the bound data. As has been said, if you want another column then add another column to the underlying DataTable that you have bound to the grid. You can then set the Expression property of that DataColumn to populate it based on the values in other columns. You've already been directed to the Expression property of the DataColumn class. Have you read the documentation for that property? I assume not but I have to wonder why not. You want help but you're not prepared to read something that will help you when someone points you to it. Don't just sit there waiting for someone to write your code for you.