Question datagridview doesn?t show the datasource

tommylej

New member
Joined
Apr 7, 2014
Messages
4
Programming Experience
Beginner
i?m trying to bind a list to a datagridview. i do that:

C#:
public void seedatagrid(List<myClass> liste2)
{
    dgv_TraceItems.DataSource =liste2;
}
and the datagridview has the data, but it doesn?t show anything.



could you help me?? how can i resolve the problem?? thank you

the class

C#:
public enum TYPE
{
    normal= 1,
    especial= 3, 
    low= 6, 
    high= 7,          
}
 

public class myClass : INotifyPropertyChanged
{
 
    private byte number;
    private TYPE type;
    private string file;
    private bool isselected;
 
    public event PropertyChangedEventHandler PropertyChanged;
 
    public byte Number
    {
        get
        {
            return this.number;
        }
        set
        {
            this.number= value;
            this.OnPropertyChanged("Number");
        }
    }
 
    public TYPE Type
    {
        get
        {
            return this.type;
        }
        set
        {
            this.type = value;
            this.OnPropertyChanged("Type");
        }
    }
 
    public string File
    {
        get
        {
            return this.file;
        }
        set
        {
            this.file = value;
            this.OnPropertyChanged("File");
        }
    }
 
    public bool IsSelected
    {
        get
        {
            return this.isselected;
        }
        set
        {
            this.isselected = value;
            this.OnPropertyChanged("IsSelected");
        }
    }
 
    public myClass(UInt32 Data, string Text)
    {            
        this.number = (byte)((Data & 0x0000FF00) >> 8);
        this.type = (TYPE)((Data & 0x00FF0000) >> 16);
        this.file = Text;
 
    }
 
    private void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
i have tried to make a datatable with the list and the datagridview doesn?t show anything. i don?t know what happends , but i have a problem with the datagridview
thank you

C#:
 public partial class MainForm : Form
    {
        ParserClass file= null;
        UC_Configuration list_to_dgv = new UC_ChannelConfiguration();        
        TestInfoClass testInfo = null;
        

        public MainForm()
        {
            InitializeComponent();
            testInfo = new TestInfoClass();
             
            testInfo.PropertyChanged += new PropertyChangedEventHandler(testInfo_PropertyChanged);
            tbTFile.DataBindings.Add(new Binding("Text", testInfo, "FileName"));
            pConfig.EnabledChanged += new EventHandler(pConfig_EnabledChanged);
            
        }

        void pConfig_EnabledChanged(object sender, EventArgs e)            
        {
            UC_Configuration oTemp = sender as UC_ChannelConfiguration;
            if (oTemp != null)
            {
                if (oTemp.Enabled == true)
                {
                    
                    file = new ParserClass(testInfo);
                   
                   
                    if (testInfo.Information != null)
                    {
                        list_to_dgv.seedatagrid(testInfo.Information);
                    }                                       
                }
                
            }
            return;
        }

        void testInfo_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender == testInfo)
            {
                if (e.PropertyName == "FileName")
                {
                    if (testInfo.FileName != String.Empty)
                    {
                        pConfig.Enabled = true;                        
                    }
                    else
                    {
                        pConfig.Enabled = false;
                    }
                }                
            }
            return;
        }

        private void btlLoad_file_Click(object sender, EventArgs e)
        {           
            OpenFileDialog openFileDialog_file = new OpenFileDialog();         
            
            openFileDialog_file.RestoreDirectory = false;
            openFileDialog_file.Multiselect = false;

            if (openFileDialog_file.ShowDialog() == DialogResult.OK)
            {
                testInfo.FileName = openFileDialog_file.FileName;
                
            }           
        }          
    }
 
Last edited:

tommylej

New member
Joined
Apr 7, 2014
Messages
4
Programming Experience
Beginner
i call it in Form.cs when there is an event, i edited the post and you can see ir, thank you
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,141
Location
Sydney, Australia
Programming Experience
10+
You're calling 'seedatagrid' against 'list_to_dgv' but I don't see anywhere that you're actually displaying the form assigned to that variable. I think the code is working exactly as you expect but you're executing it against a form that you can't see. You have probably displayed a different instance of that form class.
 

tommylej

New member
Joined
Apr 7, 2014
Messages
4
Programming Experience
Beginner
so what do i must do?? i didn?t get you say
 
Top Bottom