How to Bind Records Windows Application using Some Familiar Controls


In this Article, I am going to explain about how to bind the records using windows application for Some Familiar Controls.I have implemented Some windows controls using Database and without Database.I have post source given below

1.How to Bind Records in Gridview with CheckBoxcolumn Using Datatable Code here


DataRow dr;
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Columns.Add("Empno");
dt.Columns.Add("Amount");
dr = dt.NewRow();
dr[0] = 1;
dr[1] = "Asp.net";
dr[2] = 100;
dr[3] = 8500;
dt.Rows.Add(dr);
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Name = "checkBoxColumn";
dataGridView1.Columns.Insert(0, checkBoxColumn);
dataGridView1.DataSource = dt;

2.How to Bind Records in comboBox Using Datatable Code here

comboBox1.DataSource = dt;
comboBox1.ValueMember = "Id";
comboBox1.DisplayMember = "Name";

3.How to Bind Records in ListBox Using Datatable Code here

listBox1.DataSource = dt;
listBox1.ValueMember = "Id";
listBox1.DisplayMember = "Name";

4.How to Bind Records in Listview Using Datatable Code here

listView1.Columns.Add("ID", 70, HorizontalAlignment.Center);
listView1.Columns.Add("Name", 70, HorizontalAlignment.Center);
listView1.Columns.Add("Empno", 70, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.GridLines = true;
listView1.BackColor = Color.Yellow;
listView1.ForeColor = Color.Red;

for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
listView1.Items.Add(dt.Rows[i].ItemArray[0].ToString());
listView1.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());
}

5.How to Bind Records in Textbox,label Using Datatable Code here

label1.Text = dt.DefaultView[0][1].ToString();
textBox1.Text = dt.DefaultView[0][1].ToString();


6.How to Bind Records in Checkbox,Radiobutton Using Datatable Code here


Form1 frm = new Form1();

for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
CheckBox chk1 = new CheckBox();
RadioButton rad = new RadioButton();
rad.Name = "Name" + i;
chk1.Name = "Name" + i;
chk1.Text = dt.DefaultView[i]["Name"].ToString();
rad.Text = dt.DefaultView[i]["Name"].ToString();
panel1.Controls.Add(chk1);
panel2.Controls.Add(rad);
}



1.How to Established Connection

SqlConnection sqlcon = new SqlConnection("Data source=PC-NAME;Initial Catalog=Test;Integrated Security=True;");
DataTable dt = new DataTable();
SqlDataAdapter sqladp = new SqlDataAdapter();


2.How to Bind Records in Datagridview with Checkboxcolumn Using Database Code here

sqladp = new SqlDataAdapter("Select * from StudentDetail", sqlcon);
sqladp.Fill(dt);

DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Name = "checkBoxColumn";
dataGridView1.Columns.Insert(0, checkBoxColumn);

dataGridView1.DataSource = dt;
comboBox1.DataSource = dt;
comboBox1.ValueMember = "Id";
comboBox1.DisplayMember = "Name";

3.How to Bind Records in ListBox Using Database Code here

listBox1.DataSource = dt;
listBox1.ValueMember = "Id";
listBox1.DisplayMember = "Name";

4.How to Bind Records in ListView Using Database Code here

listView1.Columns.Add("ID", 70, HorizontalAlignment.Center);
listView1.Columns.Add("Name", 70, HorizontalAlignment.Center);
listView1.Columns.Add("Empno", 70, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.GridLines = true;
listView1.BackColor = Color.Yellow;
listView1.ForeColor = Color.Red;

for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
listView1.Items.Add(dt.Rows[i].ItemArray[0].ToString());
listView1.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());
}

5.How to Bind Records in Label,TextBox Using Database Code here

label1.Text = dt.DefaultView[0][1].ToString();
textBox1.Text = dt.DefaultView[0][1].ToString();

6.How to Bind Records in checkbox,RadionButton Using Database Code here

for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
CheckBox chk1 = new CheckBox();
RadioButton rad = new RadioButton();
rad.Name = "Name" + i;
chk1.Name = "Name" + i;
chk1.Text = dt.DefaultView[i]["Name"].ToString();
rad.Text = dt.DefaultView[i]["Name"].ToString();
panel1.Controls.Add(chk1);
panel2.Controls.Add(rad);
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: