working with gird view in windows application

Posted by Deepakji under C# on 1/28/2012 | Points: 10 | Views : 914 | Status : [Member] | Replies : 2
hi,

i am familiar with the basic of how to work with grid view in asp.net but i don't know to do in windows application so please let me know the website or notes where i can learn easily and implement in my project.




Responses

Posted by: Jomgrg on: 1/28/2012 [Member] Starter | Points: 25

Up
0
Down
Student.Designer.cs
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Name = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Session = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Mark = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Rank = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();

this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Name,
this.Session,
this.Mark,
this.Rank});
this.dataGridView1.Location = new System.Drawing.Point(28, 32);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(529, 261);
this.dataGridView1.TabIndex = 0;

this.Name.HeaderText = "Name";
this.Name.Name = "Name";

this.Session.HeaderText = "Session";
this.Session.Name = "Session";

this.MArk.HeaderText = "Mark";
this.MArk.Name = "Mark";

this.Score.HeaderText = "Rank";
this.Score.Name = "Rank";

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(685, 399);
this.Controls.Add(this.dataGridView1);
this.Name = "Student";
this.Text = "Student";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);

}
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridViewTextBoxColumn Name;
private System.Windows.Forms.DataGridViewTextBoxColumn Session;
private System.Windows.Forms.DataGridViewTextBoxColumn Mark;
private System.Windows.Forms.DataGridViewTextBoxColumn Rank;

Student.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Student: Form
{
public Student()
{
InitializeComponent();

}

//This Function You can call where you want to bind.
//Declare Name,Session,Mark,Rank and set properties.then create a List

class StudentList: List<Student> {
}
private void BindDataGrid()
{
StudentList _student = new StudentList();

_student .Add(new Student("Jom", "ClassA", 45,4));
_student .Add(new Student("Alex", "ClassA",46,3 ));
_student .Add(new Student("Anil", "ClassA", 47,2));
_student .Add(new Student("Anish", "ClassA", 48,1));

dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = _student;
//Same like you can get values from database and bind.
}

}
}




Regards,
Jom George

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Deepakji on: 1/28/2012 [Member] Starter | Points: 25

Up
0
Down
thank you

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response