datagridview实现两级显示

   void InitGrid()
        {
            //gridDataList.Add(new Person("John", "Smith"));
            //gridDataList.Add(new Person("Gabriel", "Smith"));
            //gridDataList.Add(new Person("Ashley", "Smith", "some comment"));
            //gridDataList.Add(new Person("Adrian", "Smith", "some comment"));
            //gridDataList.Add(new Person("Gabriella", "Smith", "some comment"));
            //gridControl.DataSource = gridDataList;
            string strsql = "select order_no,package_no from t_order";
            string strsql2 = "select order_no,product_no from t_orderitem";

            ConCls cls=new ConCls ();
            SqlDataAdapter dap = new SqlDataAdapter(strsql, ConCls.GetCon());
            SqlDataAdapter dap2 = new SqlDataAdapter(strsql2, ConCls.GetCon());

            DataSet ds = new DataSet();
            dap.Fill(ds, "order");
            dap2.Fill(ds, "orderitem");
         
           
            ds.Relations.Add("relations", ds.Tables["order"].Columns["order_no"], ds.Tables["orderitem"].Columns["order_no"]);

            gridControl.DataSource = ds.Tables["order"];
           
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DataGridView 是 .NET Framework 中的一个控件,可用于在 Windows 窗体应用程序中显示和编辑表格数据。要在 DataGridView实现财务软件录入凭证金额显示,可以按照以下步骤进: 1. 在 Visual Studio 中创建一个 Windows 窗体应用程序,并添加一个 DataGridView 控件。 2. 创建一个数据源并将其绑定到 DataGridView 控件。可以使用 DataSet、DataTable 或者其他数据源来存储财务凭证数据。 3. 在 DataGridView 中添加列,例如日期、摘要、借方金额、贷方金额等。 4. 为 DataGridView 中的借方金额和贷方金额列设置格式化,以便金额能够以货币格式显示。 5. 在 DataGridView 中添加事件处理程序,以便在用户输入借方金额或贷方金额时自动计算另一列的金额。 6. 可以通过设置 DataGridView 的单元格样式来对借方金额和贷方金额进颜色标记,以便用户能够更容易地区分它们。 下面是一些示例代码: ```csharp // 设置 DataGridView 中金额列的格式化 dataGridView1.Columns["借方金额"].DefaultCellStyle.Format = "c"; dataGridView1.Columns["贷方金额"].DefaultCellStyle.Format = "c"; // 添加 DataGridView 的 CellEndEdit 事件处理程序 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { // 检查用户是否输入了借方金额或贷方金额 if (e.ColumnIndex == dataGridView1.Columns["借方金额"].Index || e.ColumnIndex == dataGridView1.Columns["贷方金额"].Index) { // 获取用户输入的金额 decimal jie = 0, dai = 0; if (decimal.TryParse(dataGridView1.Rows[e.RowIndex].Cells["借方金额"].Value.ToString(), out jie) && decimal.TryParse(dataGridView1.Rows[e.RowIndex].Cells["贷方金额"].Value.ToString(), out dai)) { // 计算另一列的金额 if (e.ColumnIndex == dataGridView1.Columns["借方金额"].Index) { dataGridView1.Rows[e.RowIndex].Cells["贷方金额"].Value = (0 - jie).ToString("c"); } else { dataGridView1.Rows[e.RowIndex].Cells["借方金额"].Value = (0 - dai).ToString("c"); } } } } // 设置 DataGridView 中金额列的单元格样式 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == dataGridView1.Columns["借方金额"].Index || e.ColumnIndex == dataGridView1.Columns["贷方金额"].Index) { // 获取单元格的值 decimal value = 0; if (decimal.TryParse(e.Value.ToString(), out value)) { // 设置单元格的颜色 if (value < 0) { e.CellStyle.ForeColor = Color.Red; } else { e.CellStyle.ForeColor = Color.Black; } } } } ``` 通过以上步骤,就可以在 DataGridView实现财务软件录入凭证金额显示了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值