/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu




Friday, April 15, 2011

VB.NET Sorting in Data Grid View

For Each c In Me.DataGridView1.Columns

c.SortMode = DataGridViewColumnSortMode.NotSortable

Next

This is the DataGridView handler you need to capture the button click event.

this.dgvList.CellContentClick += new DataGridViewCellEventHandler(DGV_CellContentClick);

This is the button click handler example

#region DGV_CellContentClick

public void DGV_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

int selectedRowIndex = int.Parse(e.RowIndex.ToString());



if (this.dgvList.Columns[e.ColumnIndex] == buttonColumn && selectedRowIndex >= 0)

{

DataRow dr = DataGridViewHelper.GetDataRow(this.dgvList);

MessageBox.Show((string)dr["FirstName"]);

}

}
Read More »

Tree View Control in vb.net Code Example

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
PopulateRootLevel();
}

private void PopulateRootLevel()
{
SqlConnection objConn = new SqlConnection("Data Source=1.1.1.1;Initial Catalog=DREER_EDUCANDOS2006;User ID=sre_web;Password=xxx");
SqlCommand objCommand = new SqlCommand("select id_deficiencia,descricao,(select count(*) FROM NecessidadesEspeciais WHERE id_deficiencia_pai=sc.id_deficiencia) childnodecount FROM NecessidadesEspeciais sc where id_deficiencia_pai IS NULL", objConn);
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, TreeView1.Nodes);
}

private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection("Data Source=1.1.1.1;Initial Catalog=DREER_EDUCANDOS2006;User ID=sre_web;Password=xxx");
SqlCommand objCommand = new SqlCommand("select id_deficiencia,descricao,(select count(*) FROM NecessidadesEspeciais WHERE id_deficiencia_pai=sc.id_deficiencia) childnodecount FROM NecessidadesEspeciais sc where id_deficiencia_pai=@id_deficiencia_pai", objConn);
objCommand.Parameters.Add("@id_deficiencia_pai", SqlDbType.Int).Value = parentid;
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);
}


protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
PopulateSubLevel(Int32.Parse(e.Node.Value), e.Node);
}

private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Text = dr["descricao"].ToString();
tn.Value = dr["id_deficiencia"].ToString();
nodes.Add(tn);

//If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0);
}
}
Read More »

Recent Posts

My Blog List