在datagridview中合并两行

在datagridview中合并两行

本文介绍了在datagridview中合并两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,



我正在做一个出勤项目,我有三列

1.员工姓名

2.会议(早/晚)

3. 1月1日至1月31日

例如:



Empname Session Jan1 Jan2 Jan 3 .............................. Jan 31

Rajesh Morning P A P

晚上P P P

莫汉(Mohan)早晨A P A

晚上A A P

Karthick早晨P P P

晚上P P P



我想实现这一目标.我是编程新手.我已经绑定一个月中的几天.现在,我想通过使用行跨度来绑定empname.并希望绑定Morning& amp;直到记录结束为止的一个晚上.

代码:

Hi friends,



I am working on a attendance project, and I have three columns

1.Employee Name

2.Session(Morning / evening)

3. Jan 1 to Jan 31

example:



Empname Session Jan1 Jan2 Jan 3............... Jan 31

Rajesh Morning P A P

Evening P P P

Mohan Morning A P A

Evening A A P

Karthick Morning P P P

Evening P P P



I want to achieve this. I am pretty new to programming. I already bind days in a month. Now I wanna bind the empname by using row span. and want to bind Morning & Evening in a for until the end of the record.

code:

private void BtnClick_Click_1(object sender, EventArgs e)
        {

 dgAttendance.Columns.Clear();
            GetData("select empname from employee");
            DataGridViewColumn cb = new DataGridViewColumn();
            DataGridViewCell cell = new DataGridViewTextBoxCell();
            cb.HeaderText = "Session";
            cb.Name = "Session";
            cb.Visible = true;
            cb.Width = 70;
            cb.CellTemplate = cell;
            dgAttendance.Columns.Add(cb);
            int days = DateTime.DaysInMonth(Convert.ToInt32(cmbYear.SelectedItem), Convert.ToInt32(cboMonths.SelectedIndex + 1));
            for (int i = 1; i <= days; i++)
            {

                DataGridViewColumn cb1 = new DataGridViewColumn();
                DataGridViewCell cell1 = new DataGridViewTextBoxCell();
                cb1.HeaderText = Convert.ToString(cboMonths.Text) + i;
                cb1.Name = Convert.ToString(cboMonths.SelectedIndex) + i;
                cb1.Visible = true;
                cb1.Width = 70;
                cb1.CellTemplate = cell1;
                dgAttendance.Columns.Add(cb1);

            } }

推荐答案


这篇关于在datagridview中合并两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 05:06