Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi
I have a vb.net datagridview in which at column 0 there are duplicate dates.At column 2 I have various numbers.I want to find and to insert the smallest of these numbers for each duplicate date at column 3.
Please Help me
thanks

What I have tried:

I have a vb.net datagridview in which at column 0 there are duplicate dates.At column 2 I have various numbers.I want to find and to insert the smallest of these numbers for each duplicate date at column 3.
Please Help me
thanks
Posted
Updated 22-Mar-22 12:03pm
Comments
OriginalGriff 22-Mar-22 2:53am    
And?
What have you tried?
Where are you stuck?
What help do you need?

Use the "Improve question" widget to edit your question and provide better information.
Member 15484988 22-Mar-22 3:06am    
Suppose you have a vb.net datagridview. one column for duplicate dates . one column for numbers . I want to find the minimum of these numbers for duplicate date and insert at another column.
I have tried times and times but I failed.
please write a code to do that
thanks in advanced
Member 15484988 22-Mar-22 3:43am    
How can I label a pic from my project here?
Maciej Los 22-Mar-22 17:22pm    
Don't! Copy and paste DataGridView's data here. Then type expected result. Use "Improve question" widget.

Quote:
I have tried times and times but I failed.
please write a code to do that

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Just saying "I tried" and asking for "a code" isn't going to cut it.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Member 15484988 22-Mar-22 3:49am    
How can I send a pic from my project here?
Member 15484988 22-Mar-22 4:14am    
Something like MIN(IF( function in Excel but for VB.net
Imagine... You have a data. You store it in a DataTable[^] object, which is a DataSource[^] of your DataGridView[^] object.

Take a look at below code. There you'll find an example - how to group data by using Linq.

VB.NET
Sub Main
	
	Dim dt As DataTable = CreateSampleData()
	Dim result = dt.AsEnumerable() _
		.GroupBy(Function(x) x("DuplicatedDate")) _
		.Select(Function(grp) New With _
		{ _
			.DupDate = grp.Key, _
			.OrigValues = String.Join(", ", grp.Select(Function(x) x("SomeNumbers"))), _
			.MinValue = grp.Min(Function(x) x("SomeNumbers"))
		}) _
		.ToList()
			
			
	result.Dump()
	
End Sub

' Define other methods and classes here
Public Function CreateSampleData() As DataTable
	Dim dt As New DataTable 
	dt.Columns.Add(New DataColumn("SomeDate", Type.GetType("System.DateTime")))
	dt.Columns.Add(New DataColumn("SomeNumbers", Type.GetType("System.Int32")))
	dt.Columns.Add(New DataColumn("DuplicatedDate", Type.GetType("System.DateTime")))
	Dim r As New Random()
	For i As Integer = 1 To 20
		Dim j As Integer = (i Mod 4) + 1
		dt.Rows.Add(New Object(){New DateTime(2020, 3, i), r.Next(1,20), New DateTime(2020, 3, j)})
	Next i
	Return dt

End Function


Sample result:
DupDate             OrigValues       MinValue
2020-03-02 00:00:00 12,13,7,2,17     2 
2020-03-03 00:00:00 16,11,9,5,13     5 
2020-03-04 00:00:00 3,7,13,19,8      3 
2020-03-01 00:00:00 16,14,7,6,13     6 
 
Share this answer
 
Comments
Member 15484988 23-Mar-22 9:29am    
hithanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900