Datagridview将奇数行打印到左侧甚至右​​侧 [英] Datagridview print odd number rows to left and even to right

查看:61
本文介绍了Datagridview将奇数行打印到左侧甚至右​​侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我所有的数据网格视图由90行组成,我需要的是我想打印datagridview,以便在左侧打印奇数行,在右侧打印
偶数。附上代码请一些人帮助我

我的代码附在这里  ; http://www.c -sharpcorner.com/Forums/datagridview-print-odd-number-rows-to-left-and-even-to-right

推荐答案

您好Kaashyap,

Hi Kaashyap,

我认为您可以像显示的图片一样添加数据,然后将其打印出来,也可以从您提供的代码中添加您可以像下面的演示一样更改它:

I think you can add the data just like the picture showing and then print it, and from the code you provided, maybe you can change it just like the following demo:

        private void BindGrid()
        {
            string constring = @"Data Source=.;Initial Catalog=Northwind;Integrated Security=True";
            DataTable table = new DataTable();
            table.Columns.Add("CustomerId");
            table.Columns.Add("ContactName");
            table.Columns.Add("Country");
            table.Columns.Add("CustomerId2");
            table.Columns.Add("ContactName2");
            table.Columns.Add("Country2");

            for (int i = 1; i < 100; i++)
            {
                DataRow r = table.NewRow();
                if (i % 2 != 0)
                {
                    r["CustomerId"] = i;
                    r["ContactName"] = "Name" + i;
                    r["Country"] = "Country" + i;
                    r["CustomerId2"] = i + 1;
                    r["ContactName2"] = "Name" + (i + 1);
                    r["Country2"] = "Country" + (i + 1);
                    table.Rows.Add(r);
                }
            }

            dataGridView1.AutoGenerateColumns = false;

            //Set Columns Count
            dataGridView1.ColumnCount = 6;

            //Add Columns
            dataGridView1.Columns[0].Name = "CustomerId";
            dataGridView1.Columns[0].HeaderText = "Customer Id";
            dataGridView1.Columns[0].DataPropertyName = "CustomerID";

            dataGridView1.Columns[1].HeaderText = "Contact Name";
            dataGridView1.Columns[1].Name = "Name";
            dataGridView1.Columns[1].DataPropertyName = "ContactName";

            dataGridView1.Columns[2].Name = "Country";
            dataGridView1.Columns[2].HeaderText = "Country";
            dataGridView1.Columns[2].DataPropertyName = "Country";

            dataGridView1.Columns[3].Name = "CustomerId2";
            dataGridView1.Columns[3].HeaderText = "CustomerId2";
            dataGridView1.Columns[3].DataPropertyName = "CustomerId2";

            dataGridView1.Columns[4].Name = "ContactName2";
            dataGridView1.Columns[4].HeaderText = "ContactName2";
            dataGridView1.Columns[4].DataPropertyName = "ContactName2";

            dataGridView1.Columns[5].Name = "Country2";
            dataGridView1.Columns[5].HeaderText = "Country2";
            dataGridView1.Columns[5].DataPropertyName = "Country2";
            dataGridView1.DataSource = table;
        }

希望有所帮助!

最好的问候,

Stanly


这篇关于Datagridview将奇数行打印到左侧甚至右​​侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆