[SOLVED!!] datagridview add rank number column then my data (pictures or text)
HELLO Everyone :wave:, so i am trapped with a problem. i can load a pictures or text but i can' t do a rank number column
for pictures i have this code:
Dim newItems() As String = ListBox2.Items.Cast(Of String).Select(Function(s) s.Split(" "c).Last & " " & s.Split(" "c).First).ToArray
For Each Item As String In ListBox2.Items
Dim imgx As Image
imgx = Image.FromFile(Application.StartupPath & "\DANfiles\challengersgif" & Item.Substring(Item.IndexOf(" ") + 1) & ".png")
DataGridView2.Rows.Add(imgx)
Next
for data, i have this code:
DataGridView1.DataSource = Enumerable.Range(1, newItems.Length).
Select(Function(n) New With {.Rank = n, .Name = newItems(n - 1)}).
ToArray()
now, i have two datagridview to display my data but i would like to merge the both in order to have this result in one datagridview:
rank image text
example
1 picture text
2 picture text
3 picture text
4 picture text
5 picture text
I miss me a clever codes to solve my problem definitively.
i beg your help for this. thank you in advance for your help
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
This works...
Code:
Dim newItems() As String = ListBox2.Items.Cast(Of String).Select(Function(s) s.Split(" "c).Last & " " & s.Split(" "c).First).ToArray
DataGridView1.DataSource = Enumerable.Range(1, newItems.Length).
Select(Function(n) New With {.Rank = n, .Image = Image.FromFile(Application.StartupPath & "\DANfiles\challengersgif" & newItems(n-1).Substring(newItems(n-1).IndexOf(" ") + 1) & ".png"), .Name = newItems(n - 1)}).
ToArray()
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
Quote:
Originally Posted by
.paul.
This works...
Code:
Dim newItems() As String = ListBox2.Items.Cast(Of String).Select(Function(s) s.Split(" "c).Last & " " & s.Split(" "c).First).ToArray
DataGridView1.DataSource = Enumerable.Range(1, newItems.Length).
Select(Function(n) New With {.Rank = n, .Image = Image.FromFile(Application.StartupPath & "\DANfiles\challengersgif" & newItems(n-1).Substring(newItems(n-1).IndexOf(" ") + 1) & ".png"), .Name = newItems(n - 1)}).
ToArray()
it is almost that but the image don' t load because the name of png is wrong. indeed, the names from lisbox 2 is for example 25555 PAUL and i just need "PAUL" .
the code return me 25555.png for the picture.
could you give the necessary code to fix it thank you for you help!
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
Is it always the last single word in the listbox item?
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
Because, the third column would probably show that which you’re guessing is the filename, but in the image column, there is far more likely to be a different error in the image path...
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
Quote:
Originally Posted by
.paul.
Is it always the last single word in the listbox item?
yes ! it is the names!
for example;
11200 anna
11180 eric
10200 marc
10110 davon
a number separete by a blank " " then the name
the pictures are from the names <<<example for 11200 anna my picture name is anna.png and so on
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
The following provides rank the sort and note as is will not permit sorting in the DataGridView but replace the list with a DataTable it will be sortable in the DataGridView but if you want the rank the sort there is no need to provide sorting.
Code:
Public Class Dataitem
Public Property Rank() As Integer
Public Property ImageName() As String
End Class
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dataItemList As New List(Of Dataitem)
Dim data = New List(Of String) From {"11200 anna", "11180 eric", "10200 marc", "10110 davon"}
For Each currentItem As String In data
Dim item = currentItem
Dim digits = CInt(String.Concat(From c In item Select c Where Char.IsDigit(c)))
Dim alphas = String.Concat(From c In item Select c Where Not Char.IsDigit(c) AndAlso
Not Char.IsWhiteSpace(c)) & ".png"
dataItemList.Add(New Dataitem() With {.Rank = digits, .ImageName = alphas})
Next
DataGridViewResults.DataSource = dataItemList.OrderBy(Function(dataitem) dataitem.Rank).ToList()
DataGridViewResults.Columns("ImageName").HeaderText = "Name"
End Sub
Once you have the above and done with a DataTable simply load images into a DataColumn of type byte array should work.
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
Quote:
Originally Posted by
kareninstructor
The following provides rank the sort and note as is will not permit sorting in the DataGridView but replace the list with a DataTable it will be sortable in the DataGridView but if you want the rank the sort there is no need to provide sorting.
Code:
Public Class Dataitem
Public Property Rank() As Integer
Public Property ImageName() As String
End Class
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dataItemList As New List(Of Dataitem)
Dim data = New List(Of String) From {"11200 anna", "11180 eric", "10200 marc", "10110 davon"}
For Each currentItem As String In data
Dim item = currentItem
Dim digits = CInt(String.Concat(From c In item Select c Where Char.IsDigit(c)))
Dim alphas = String.Concat(From c In item Select c Where Not Char.IsDigit(c) AndAlso
Not Char.IsWhiteSpace(c)) & ".png"
dataItemList.Add(New Dataitem() With {.Rank = digits, .ImageName = alphas})
Next
DataGridViewResults.DataSource = dataItemList.OrderBy(Function(dataitem) dataitem.Rank).ToList()
DataGridViewResults.Columns("ImageName").HeaderText = "Name"
End Sub
Once you have the above and done with a DataTable simply load images into a DataColumn of type byte array should work.
thank you so much ! i solved my problem thank to paul and you ! i edited my code like this:
Dim newItems() As String = Form1.ListBox2.Items.Cast(Of String).Select(Function(s) s.Split(" "c).Last & " " & s.Split(" "c).Last).ToArray
Dim newItemsA() As String = Form1.ListBox2.Items.Cast(Of String).Select(Function(s) s.Split(" "c).Last & " " & s.Split(" "c).First).ToArray
Form1.DataGridView2.DataSource = Enumerable.Range(1, newItems.Length).
Select(Function(n) New With {.Rank = n, .Image = Image.FromFile(Application.StartupPath & "\DANfiles\challengersgif" & newItems(n - 1).Substring(newItems(n - 1).IndexOf(" ") + 1) & ".png"), .Name = newItemsA(n - 1)}).
ToArray()
but i am very happy and grateful for your help . have a nice day!
my regards.