تقييم الموضوع :
  • 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 ك ب / التحميلات : 15)
الرد }}}
#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
الرد }}}


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  تعديل بيانات عمود DataGridView دفعة واحدة مصمم هاوي 2 164 05-03-24, 08:27 PM
آخر رد: مصمم هاوي
  فلترة datagridview بدون قاعدة بيانات صالح عبدالله 3 295 02-02-24, 04:07 PM
آخر رد: صالح عبدالله
  [VB.NET] ظهور التاريخ غير مرتب بالأقدم في datagridview مبرمج صغير 1 4 304 26-01-24, 03:41 PM
آخر رد: atefkhalf2004
  [VB.NET] التاريخ في أداة أبو سامر لطباعة DataGridView مبرمج صغير 1 17 629 26-01-24, 01:52 AM
آخر رد: مبرمج صغير 1
  مشكلة في datagridview Adata 4 310 17-01-24, 03:00 PM
آخر رد: aljzazy
  [سؤال] كيفية انشاء فورم داخل مشروعى عاصم النجار 2 305 05-01-24, 12:36 AM
آخر رد: HALIM ELEULMA
  حماية عمود داخل ورقة الاكسل العيدروس 3 190 05-01-24, 12:21 AM
آخر رد: HALIM ELEULMA
Lightbulb [VB.NET] إطهار الصورة بمقاس معين في DataGridView أبو خالد الشكري 2 323 14-12-23, 03:01 PM
آخر رد: أبو خالد الشكري
Question [VB.NET] اسم عمود الأرقام في DataGridView أبو خالد الشكري 6 606 03-12-23, 08:01 AM
آخر رد: أبو خالد الشكري
  [VB.NET] Datagridview Slow حركة بطيئة waataanys 1 294 20-11-23, 04:33 PM
آخر رد: justforit

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


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم