-
Jun 12th, 2020, 07:51 PM
#1
Thread Starter
Lively Member
[SOLVED!!] datagridview add rank number column then my data (pictures or text)
HELLO Everyone , 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
Last edited by danzey; Jun 13th, 2020 at 06:24 AM.
-
Jun 12th, 2020, 08:04 PM
#2
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()
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 12th, 2020, 10:30 PM
#3
Thread Starter
Lively Member
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
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!
-
Jun 12th, 2020, 10:41 PM
#4
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?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 12th, 2020, 11:08 PM
#5
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 13th, 2020, 04:20 AM
#6
Thread Starter
Lively Member
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
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
Last edited by danzey; Jun 13th, 2020 at 04:35 AM.
-
Jun 13th, 2020, 06:05 AM
#7
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.
-
Jun 13th, 2020, 06:23 AM
#8
Thread Starter
Lively Member
Re: [HELP PLEASE] datagridview add rank number column then my data (pictures or text)
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.
Tags for this Thread
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
|