C# (C Sharp) Beginner | Tutorial | Learning | Study
C# (C Sharp) Beginner | Tutorial | Learning | Study
2 March 2017
6 August 2016
Add Item in Datagridview Combobox Column in C#
DatagridviewComboBox otype = new DatagridviewComboBox ( );
otype.Items.Add("Item1");
otype.Items.Add("Item2");
otype.Items.Add("Item1");
otype.Items.Add("Item2");
5 August 2016
Delete selected Multiple Rows in Datagridview in C#
foreach(DataGridViewRow dR in DGV.SelectedRows)
{
DGV.Rows.Remove(dR);
}
That's All; Simple....!
Thank you!
{
DGV.Rows.Remove(dR);
}
That's All; Simple....!
Thank you!
4 August 2016
Switch case in C#
private void DGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
switch (e.ColumnIndex)
{
case 1:
p1.cmd = new OleDbCommand("select pname from pmaster where code='" + DGV[e.ColumnIndex, e.RowIndex].Value + "'", p1.Cn);
p1.rs = p1.cmd.ExecuteReader();
if(p1.rs.Read()) DGV[e.ColumnIndex + 1, e.RowIndex].Value = p1.rs[0];
break;
case 2:
break;
default:
break;
}
}
{
switch (e.ColumnIndex)
{
case 1:
p1.cmd = new OleDbCommand("select pname from pmaster where code='" + DGV[e.ColumnIndex, e.RowIndex].Value + "'", p1.Cn);
p1.rs = p1.cmd.ExecuteReader();
if(p1.rs.Read()) DGV[e.ColumnIndex + 1, e.RowIndex].Value = p1.rs[0];
break;
case 2:
break;
default:
break;
}
}
3 August 2016
Add Rows and Row Data by Programmatically in Datagridview C#
Fill Controls by Double click Cell in datagridview in C#
private void DGV_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
C1.Text = DGV["lno", e.RowIndex].Value.ToString();
DT.Value = Convert.ToDateTime(DGV["date1", e.RowIndex].Value);
C2.Text = DGV["pcode", e.RowIndex].Value.ToString();
textBox11.Text = DGV["tcode", e.RowIndex].Value.ToString();
C3.Text = DGV["pname", e.RowIndex].Value.ToString();
C4.Text = DGV["sname", e.RowIndex].Value.ToString();
C5.Text = DGV["type1", e.RowIndex].Value.ToString();
C6.Text = DGV["type2", e.RowIndex].Value.ToString();
textBox1.Text = DGV["qty", e.RowIndex].Value.ToString();
textBox2.Text = DGV["gram", e.RowIndex].Value.ToString();
}
Write to murugankarthik@gmail.com for more.
{
C1.Text = DGV["lno", e.RowIndex].Value.ToString();
DT.Value = Convert.ToDateTime(DGV["date1", e.RowIndex].Value);
C2.Text = DGV["pcode", e.RowIndex].Value.ToString();
textBox11.Text = DGV["tcode", e.RowIndex].Value.ToString();
C3.Text = DGV["pname", e.RowIndex].Value.ToString();
C4.Text = DGV["sname", e.RowIndex].Value.ToString();
C5.Text = DGV["type1", e.RowIndex].Value.ToString();
C6.Text = DGV["type2", e.RowIndex].Value.ToString();
textBox1.Text = DGV["qty", e.RowIndex].Value.ToString();
textBox2.Text = DGV["gram", e.RowIndex].Value.ToString();
}
Write to murugankarthik@gmail.com for more.
Set Columns in Datagridview C#
void seTFlx()
{
DataGridViewTextBoxColumn cS = new DataGridViewTextBoxColumn();
DataGridViewComboBoxColumn cBc = new DataGridViewComboBoxColumn();
DataGridViewComboBoxColumn cBc1 = new DataGridViewComboBoxColumn();
cS.HeaderText = "S.No";
cBc.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
p1.cmd = new OleDbCommand("select pname from pmaster", p1.Cn);
p1.rs = p1.cmd.ExecuteReader();
while (p1.rs.Read())
{
cBc.Items.Add(p1.rs[0]);
cBc1.Items.Add(p1.rs[0]);
}
DGV.Columns.Add(cS);
DGV.Columns.Add(cBc);
DGV.Columns.Add(cBc1);
DGV.Rows.Add(100);
for (int s = 0; s < 100; s++)
{
DGV[0, s].Value = s + 1;
}
DGV.Columns[0].ReadOnly = true;
}
{
DataGridViewTextBoxColumn cS = new DataGridViewTextBoxColumn();
DataGridViewComboBoxColumn cBc = new DataGridViewComboBoxColumn();
DataGridViewComboBoxColumn cBc1 = new DataGridViewComboBoxColumn();
cS.HeaderText = "S.No";
cBc.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
p1.cmd = new OleDbCommand("select pname from pmaster", p1.Cn);
p1.rs = p1.cmd.ExecuteReader();
while (p1.rs.Read())
{
cBc.Items.Add(p1.rs[0]);
cBc1.Items.Add(p1.rs[0]);
}
DGV.Columns.Add(cS);
DGV.Columns.Add(cBc);
DGV.Columns.Add(cBc1);
DGV.Rows.Add(100);
for (int s = 0; s < 100; s++)
{
DGV[0, s].Value = s + 1;
}
DGV.Columns[0].ReadOnly = true;
}
23 July 2016
Crystal Report in C#
1) Add Reference as following
2) Add Axcrviewer9Lib view in form from Toolbox and rename control to CRV
3) Then copy this to your code section
private void print_Load(object sender, EventArgs e)
{
CRAXDRT.Application crep = new CRAXDRT.Application();
CRAXDRT.Report frep = new CRAXDRT.Report();
this.Text = "Test Print";
frep = crep.OpenReport("D:/Sofwares/Adagu/loan_rep.rpt", 1);
p1.cmd = new OleDbCommand("select *,'Loan Report' as rname from loan", p1.Cn);
p1.rs = p1.cmd.ExecuteReader();
p1.rs.Read();
frep.Database.SetDataSource(p1.rs);
CRV.ViewReport();
MessageBox.Show("Printed Successful");
}
For more Details Mail to murugankarthik008@gmail.com
MsAccess Database Connection with C#
using System.Data.OleDb;
Cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Data.mdb");
Cn.Open();
Cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Data.mdb");
Cn.Open();
How to save datagridview to access database c#
for(int i = 0; i < DGV.Rows.Count - 1; i++)
{
p1.cmd = new OleDbCommand("insert into pmaster(name,sname,type,gro,code,odate) values ('" + C2.Text.Trim() + "','" + DGV[1,i]+"','"+C3.Text+"','"+C1.Text.Trim()+"','"+textBox1.Text.Trim()+"','"+DateTime.Now.Date+"')",p1.Cn);
p1.cmd.ExecuteNonQuery();
}
{
p1.cmd = new OleDbCommand("insert into pmaster(name,sname,type,gro,code,odate) values ('" + C2.Text.Trim() + "','" + DGV[1,i]+"','"+C3.Text+"','"+C1.Text.Trim()+"','"+textBox1.Text.Trim()+"','"+DateTime.Now.Date+"')",p1.Cn);
p1.cmd.ExecuteNonQuery();
}
Subscribe to:
Posts (Atom)