I am working on winforms application. On my form I simply drag and drop a DataGridView control and then set some of its properties using the properties window. Following is the code which I am using to populate my DataGridView. I wrote this code inside the constructor.
List<MyCustomClass> lst = new List<MyCustomClass>();
lst = LoadList(/*some params here*/);//now uptil this point everything works i.e the list contains values as desribed.
dataGridView1.DataSource = lst;
The problem is that when i run the program nothing is displayed in my DataGridView.
For more details following code represents the properties which I set using properties window
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.AllowUserToResizeRows = false;
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.GridColor = System.Drawing.Color.White;
this.dataGridView1.Location = new System.Drawing.Point(2, 329);
this.dataGridView1.Margin = new System.Windows.Forms.Padding(2);
this.dataGridView1.MultiSelect = false;
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersVisible = false;
this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView1.Size = new System.Drawing.Size(334, 106);
this.dataGridView1.TabIndex = 0;
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.
I've got nearly the same thing today, the problem was that my clas had public fields, not properties, since i've changed them to public auto properties - worked well for me.
You have to create Data Columns for your datagrid. Make sure you also set 'DataPropertyName' property of each column with the respected DataSource item's property (i.e., property of 'MyCustomClass' class).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With