Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello;
I have a datagrid and more coloumns in my wpf project. I want to fill coloumns one by one something items. I tried someway but I don't it. I mean; I want to fill one by one fill coloumns. How do I?
I'm sorry very bad english.

What I have tried:

static Dictionary<string, Tags> m_showChipList = new Dictionary<string, Tags>();

epc = 1234555622344;
tid = 2223444222134;
pathpcbit = @".\Resources\cross.png";
m_showChipList.Add(writeResult.Tag.Tid.ToString(),
                                      new Tags
                                      {
                                          PCBit = pathpcbit
                                      });

public class Tags {
     public int NUM { get; set; }
     public string TID { get; set; }
     public string EPC { get; set; }
     public string PCBit { get; set; }
     public string WEPC { get; set; }
     public string UACCESS { get; set; }
     public string UKILL { get; set; }
     public string WACCESS { get; set; }
     public string WKILL { get; set; }
     public string LACCESS { get; set; }
     public string LKILL { get; set; }
     public string CEPC { get; set; }
     public string CACCESS { get; set; }
     public string CKILL { get; set; }
     public string CLACCESS { get; set; }
     public string CLKILL { get; set; }
 }

PCB.Add(new Tags()
                        {
                            NUM = i,
                            TID = tag.Tid.ToString(),
                            EPC = tag.Epc.ToString(),
                            PCBit = m_showChipList[tag.Tid.ToString()].PCBit,
                            WEPC = m_showChipList[tag.Tid.ToString()].WEPC,
                            UACCESS = m_showChipList[tag.Tid.ToString()].UACCESS,
                            UKILL = m_showChipList[tag.Tid.ToString()].UKILL,
                            WACCESS = m_showChipList[tag.Tid.ToString()].WACCESS,
                            WKILL = m_showChipList[tag.Tid.ToString()].WKILL,
                            LACCESS = m_showChipList[tag.Tid.ToString()].LACCESS,
                            LKILL = m_showChipList[tag.Tid.ToString()].LKILL,
                            CEPC = m_showChipList[tag.Tid.ToString()].CEPC,
                            CACCESS = m_showChipList[tag.Tid.ToString()].CACCESS,
                            CKILL = m_showChipList[tag.Tid.ToString()].CKILL,
                            CLACCESS = m_showChipList[tag.Tid.ToString()].CLACCESS,
                            CLKILL = m_showChipList[tag.Tid.ToString()].CLKILL

                        }); PCBProgrammer.Items.Add(PCB);
Posted
Updated 14-Sep-20 23:02pm

1 solution

I would suggest you to start by reading about MVVM:
Model-View-ViewModel (MVVM) Explained[^]
MVVM for Beginners[^]

You would setup a model that is a collection for your grid as source. Columns in it mapped to fields in the object type you made collection of.

Now, in your case above, if you want to do it using a dictionary, it would be something like:
HTML
<Window x:Class="DictionaryDataGridDemo.SingleDictView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DictionaryDataGridDemo" 
    Title="test"
    Width="500"
    Height="300">
    <Window.DataContext>
        <local:MyViewModel />
    </Window.DataContext>
    <Grid>
        <DataGrid AutoGenerateColumns="True" ItemsSource="{Binding MyDictionary}">
        </DataGrid>
    </Grid>
</Window>

ViewModel
C#
public class MyViewModel
{
    public Dictionary<double, string> MyDictionary { get; set; }

    public MyViewModel()
    {
        MyDictionary = new Dictionary<double, string>();
        MyDictionary.Add(100, "AAA100");
        MyDictionary.Add(200, "BBB200");
        MyDictionary.Add(300, "CCC300");
    }
}
 
Share this answer
 
v2
Comments
Member 14922390 15-Sep-20 13:03pm    
Modify the comment. Deleted
Firstly thank you for your reply and I will try but I want to asking one point. My xaml is same this: <datagrid.columns>
<datagridtextcolumn header="NUM" binding="{Binding NUM}">
<datagridtextcolumn header="TID" binding="{Binding TID}">
<datagridtextcolumn header="EPC" bağlama="{Binding EPC}">
<datagridtemplatecolumn header="PCBit">
<datagridtemplatecolumn.celltemplate>
<datemplate>




<datagridtemplatecolumn header="WEPC">
<datagridtemplatecolumn.celltemplate>
<datatemplate>




if I read epc successfully I will fill second .But I havent any idea. How do I?

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