1.TreeView控件(导航菜单)的运用

 在这里给大家介绍一个方法,就是将菜单栏与导航菜单结合使用,导航菜单的增删情况与菜单栏同步:

 贴出用C#的代码:

  

代码
public void GetMenu(TreeView treeV,MenuStrip MenuS)
{
for (int i = 0; i < MenuS.Items.Count; i++)
{
TreeNode newNode1
= treeV.Nodes.Add(MenuS.Items[i].Text);
ToolStripDropDownItem newmenu
= (ToolStripDropDownItem)MenuS.Items[i];
if(newmenu.HasDropDownItems && newmenu.DropDownItems.Count > 0)
for (int j = 0; j < newmenu.DropDownItems.Count; j++)
{
TreeNode newNode2
= newNode1.Nodes.Add(newmenu.DropDownItems[j].Text);
ToolStripDropDownItem newmenu2
= (ToolStripDropDownItem)newmenu.DropDownItems[j];
if (newmenu2.HasDropDownItems && newmenu2.DropDownItems.Count > 0)
for (int p = 0; p < newmenu2.DropDownItems.Count; p++)
newNode2.Nodes.Add(newmenu2.DropDownItems[p].Text);
}
}
}
//树状图

 

2.将comboBox控件与数据库中相应数据绑定:

  

comboBox1.DataSource = tb1.select_type(strSQL).Tables[0];
comboBox1.DisplayMember
= "itemtype"; //绑定的字段名称

 

 

3.如何表示datagridview控件选中的那一行的数据:

  

mystr = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
value
= this.dataGridView1.SelectedRows[0].Cells[6].Value.ToString();

 

4.如何去掉datagridview的默认光标:

 

dataGridView2.ClearSelection(); //去掉默认光标

 

datagridview的光标移动:

dataGridView1.CurrentCell = this.dataGridView1[0, dataGridView1.CurrentCell.RowIndex + 1];
//光标下移

 

5.datagridview的刷新问题:

   当数据库中的数据发生改变的时候,如何及时刷新datagridview:

 贴上一段用C#写好的代码:

   只需要重新对数据源再绑定一次就可以了。

dataGridView2.DataSource = tb1.exam_refurbish("select tem_ID 题目编号,tem_result 答案 from tem_testpaper").Tables[0];
  
public DataSet exam_refurbish(string strSQL)  //刷新datagridview控件
        {
            conn.Find_data(strSQL);
            if (conn.D_S().Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("找不到相应数据", "提示");
                return null;
            }
            else
            {
                return conn.D_S();
            }
        }

 

 

6.如何在 DataGridView前面加上一列复选框:

       

DataGridViewCheckBoxColumn dc = new DataGridViewCheckBoxColumn();
dc.Name
= "选择";
this.dataGridView1.Columns.Add(dc);

 

 7. 如何使DataGridView的列名全部在可视范围内:

   通过设置DataGridView的AutoSize ColumnsMode = Fill 可以实现

 

 

 

 

posted on 2010-05-22 17:24  guolebin7  阅读(715)  评论(2编辑  收藏  举报