تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
عرض Object داخل Datagridview?
#1
السلام عليكم ورحمة الله وبركاته

عندي  قائمة List وداخلها قاموس هل يوجد طريقة لعرضها داخل Datagridview   او Listview?

هذا مثال :
كود :
Public Class Profile
   Property Name As String
   Property isWork As Boolean
   Property Informations As New Dictionary(Of String, String)

End Class

كود :
Dim ProfileList As New List(Of Profile)

       Dim p1 As New Profile
       p1.Name = "Omar"
       p1.isWork = True
       p1.Informations.Add("Address", "KSA")
       p1.Informations.Add("Age", "23")
       p1.Informations.Add("Phone", "09485433")
       Dim p2 As New Profile
       p2.Name = "Samy"
       p2.isWork = False
       p2.Informations.Add("Address", "Egypt")
       p2.Informations.Add("Age", "22")
       p2.Informations.Add("Phone", "0665573")
       Dim p3 As New Profile
       p3.Name = "Ahmad"
       p3.isWork = True
       p3.Informations.Add("Address", "Morocco")
       p3.Informations.Add("Age", "24")
       p3.Informations.Add("Phone", "6565573")
       Dim p4 As New Profile
       p4.Name = "Amar"
       p4.isWork = False
       p4.Informations.Add("Address", "Jordan")
       p4.Informations.Add("Age", "25")
       p4.Informations.Add("Phone", "6565573")
       ProfileList.Add(p1)
       ProfileList.Add(p2)
       ProfileList.Add(p3)
       ProfileList.Add(p4)
كيف اعرض  هذا Object داخل Datagridview  ?
ويكون العرض هكذا
كود :
Name        isWork         Key             Value
Amar        False           Address      Jordan
Amar        False           Age             25
Amar        False           Phone         6565573
Ahmad      True            Address      Morocco
Ahmad      True            Age             24
Ahmad      True            Phone         6565573
etc..
اثنان لا يتعلمان المتكبر والخجول
Heart اللهم علمنا ما ينفعنا و انفعنا بما علمتنا وَ زِدْنا علماً‏ Heart
الرد }}}
تم الشكر بواسطة: سعود
#2
و عليكم  السلام ورحمة الله وبركاته


الكلاسات بعد التعديل:
PHP كود :
Public Class Class1
    Public 
Function GetProfile() As List(Of Profile)
 
       Dim ProfileList As New List(Of Profile)
 
       Dim p1 As New Profile
        p1
.Name "Omar"
 
       p1.isWork True
        p1
.Informations.Add("Address""KSA")
 
       p1.Informations.Add("Age""23")
 
       p1.Informations.Add("Phone""09485433")
 
       Dim p2 As New Profile
        p2
.Name "Samy"
 
       p2.isWork False
        p2
.Informations.Add("Address""Egypt")
 
       p2.Informations.Add("Age""22")
 
       p2.Informations.Add("Phone""0665573")
 
       Dim p3 As New Profile
        p3
.Name "Ahmad"
 
       p3.isWork True
        p3
.Informations.Add("Address""Morocco")
 
       p3.Informations.Add("Age""24")
 
       p3.Informations.Add("Phone""6565573")
 
       Dim p4 As New Profile
        p4
.Name "Amar"
 
       p4.isWork False
        p4
.Informations.Add("Address""Jordan")
 
       p4.Informations.Add("Age""25")
 
       p4.Informations.Add("Phone""6565573")
 
       ProfileList.Add(p1)
 
       ProfileList.Add(p2)
 
       ProfileList.Add(p3)
 
       ProfileList.Add(p4)
 
       Return ProfileList
    End 
Function
End Class
Public Class 
Profile
    Property Name 
As String
    Property isWork 
As Boolean
    Property Informations 
As New Dictionary(Of StringString)
End Class 

والتالي اجراء من زر في فورم
PHP كود :
       d.Rows.Clear()
 
       Dim c As New Class1
        For Each pro 
As Profile In c.GetProfile
            d
.Rows.Add(pro.Namepro.isWorkpro.Informations.Keys(0), pro.Informations.Values(0), pro.Informations.Keys(1), pro.Informations.Values(1), pro.Informations.Keys(2), pro.Informations.Values(2))
 
       Next 

تعديل على الفورم فقط

PHP كود :
Public Class Form1
    Private Sub createcolls
()
 
       d.ColumnCount 5
        d
.Columns(0).HeaderText "Name"
 
       d.Columns(1).HeaderText "Is Work"
 
       d.Columns(2).HeaderText "Address"
 
       d.Columns(3).HeaderText "Age"
 
       d.Columns(4).HeaderText "Phone"
 
       d.AutoSizeColumnsMode DataGridViewAutoSizeColumnsMode.Fill
    End Sub

    Private Sub Button1_Click
(sender As ObjectAs EventArgsHandles Button1.Click
        d
.Rows.Clear()
 
       Dim c As New Class1
        For Each pro 
As Profile In c.GetProfile
            d
.Rows.Add(pro.Namepro.isWorkpro.Informations.Values(0), pro.Informations.Values(1), pro.Informations.Values(2))
 
       Next
    End Sub

    Private Sub Form1_Load
(sender As ObjectAs EventArgsHandles MyBase.Load
        createcolls
()
 
   End Sub
End 
Class 


المثال البسيط مرفق


الملفات المرفقة
.zip   For_silverlord.zip (الحجم : 12.52 ك ب / التحميلات : 22)
اللهم إني أعوذ بك من غلبة الدين وغلبة العدو، اللهم إني أعوذ بك من جهد البلاء ومن درك الشقاء ومن سوء القضاء ومن شماتة الأعداء
اللهم اغفر لي خطيئتي وجهلي، وإسرافي في أمري وما أنت أعلم به مني، اللهم اغفر لي ما قدمت وما أخرت، وما أسررت وما أعلنت وما أنت أعلم به مني، أنت المقدم وأنت المؤخر وأنت على كل شيء قدير
الرد }}}
#3
(03-07-22, 11:09 PM)سعود كتب : و عليكم  السلام ورحمة الله وبركاته


الكلاسات بعد التعديل:
PHP كود :
Public Class Class1
    Public 
Function GetProfile() As List(Of Profile)
 
       Dim ProfileList As New List(Of Profile)
 
       Dim p1 As New Profile
        p1
.Name "Omar"
 
       p1.isWork True
        p1
.Informations.Add("Address""KSA")
 
       p1.Informations.Add("Age""23")
 
       p1.Informations.Add("Phone""09485433")
 
       Dim p2 As New Profile
        p2
.Name "Samy"
 
       p2.isWork False
        p2
.Informations.Add("Address""Egypt")
 
       p2.Informations.Add("Age""22")
 
       p2.Informations.Add("Phone""0665573")
 
       Dim p3 As New Profile
        p3
.Name "Ahmad"
 
       p3.isWork True
        p3
.Informations.Add("Address""Morocco")
 
       p3.Informations.Add("Age""24")
 
       p3.Informations.Add("Phone""6565573")
 
       Dim p4 As New Profile
        p4
.Name "Amar"
 
       p4.isWork False
        p4
.Informations.Add("Address""Jordan")
 
       p4.Informations.Add("Age""25")
 
       p4.Informations.Add("Phone""6565573")
 
       ProfileList.Add(p1)
 
       ProfileList.Add(p2)
 
       ProfileList.Add(p3)
 
       ProfileList.Add(p4)
 
       Return ProfileList
    End 
Function
End Class
Public Class 
Profile
    Property Name 
As String
    Property isWork 
As Boolean
    Property Informations 
As New Dictionary(Of StringString)
End Class 

والتالي اجراء من زر في فورم
PHP كود :
       d.Rows.Clear()
 
       Dim c As New Class1
        For Each pro 
As Profile In c.GetProfile
            d
.Rows.Add(pro.Namepro.isWorkpro.Informations.Keys(0), pro.Informations.Values(0), pro.Informations.Keys(1), pro.Informations.Values(1), pro.Informations.Keys(2), pro.Informations.Values(2))
 
       Next 

تعديل على الفورم فقط

PHP كود :
Public Class Form1
    Private Sub createcolls
()
 
       d.ColumnCount 5
        d
.Columns(0).HeaderText "Name"
 
       d.Columns(1).HeaderText "Is Work"
 
       d.Columns(2).HeaderText "Address"
 
       d.Columns(3).HeaderText "Age"
 
       d.Columns(4).HeaderText "Phone"
 
       d.AutoSizeColumnsMode DataGridViewAutoSizeColumnsMode.Fill
    End Sub

    Private Sub Button1_Click
(sender As ObjectAs EventArgsHandles Button1.Click
        d
.Rows.Clear()
 
       Dim c As New Class1
        For Each pro 
As Profile In c.GetProfile
            d
.Rows.Add(pro.Namepro.isWorkpro.Informations.Values(0), pro.Informations.Values(1), pro.Informations.Values(2))
 
       Next
    End Sub

    Private Sub Form1_Load
(sender As ObjectAs EventArgsHandles MyBase.Load
        createcolls
()
 
   End Sub
End 
Class 


المثال البسيط مرفق
شكرا لك اخي سعود
اثنان لا يتعلمان المتكبر والخجول
Heart اللهم علمنا ما ينفعنا و انفعنا بما علمتنا وَ زِدْنا علماً‏ Heart
الرد }}}


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [سؤال] طريقة توسيط النص داخل اداة comboBox سمير1404 7 3,858 24-08-25, 01:01 PM
آخر رد: أبو خالد الشكري
  [VB.NET] محتاج اربط DataGridView بزر بحث bakrycold 1 552 28-02-25, 12:11 AM
آخر رد: bakrycold
  [VB.NET] استعراض بيانات في Datagridview واضافة جميع البيانات لجدول محدد sql skode 0 489 12-01-25, 12:50 AM
آخر رد: skode
Information [VB.NET] تنسيق أعمدة DataGridView أبو خالد الشكري 3 575 21-12-24, 02:40 PM
آخر رد: aljzazy
  استدعاء من جدولين داخل اداه FlowLayoutPanel برجاء الافادة للضرورة جداً modymody300894 7 634 15-11-24, 11:02 AM
آخر رد: modymody300894
  كتابه عدد معين من الارقام داخل تيكست بوكس modymody300894 3 555 07-11-24, 09:15 PM
آخر رد: modymody300894
  ترتيب شجره الحسابات داخل الجريد فيو modymody300894 2 409 31-10-24, 12:27 PM
آخر رد: modymody300894
Exclamation [VB.NET] ممكن عمل كود لحفظ المكتوب داخل اداة TextBox الورد الصناعي 9 797 17-10-24, 11:43 PM
آخر رد: salamandal
  ارجو المساعدة في كود مقارنة عامود داخل الداتا جريد فيو alachk 11 1,085 11-08-24, 11:44 AM
آخر رد: alachk
Exclamation [VB.NET] اريد كود لتصدير البيانات من DataGridView الى ملف Excel zazasami 1 496 04-08-24, 09:15 PM
آخر رد: mrfenix93

التنقل السريع :


يقوم بقرائة الموضوع: