在datagridview中合并两行 [英] Merge two rows in datagridview

查看:92
本文介绍了在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);

            } }

推荐答案

好..我不太了解您的问题..但我想您想在数据行成员之间创建一个关系(一种合并多行)..在这种情况下,您需要调用DataRelationDataColumn类.

阅读下面的链接,它会带给您很多洞察力.它非常简单容易:)

http://msdn.microsoft.com/en-us/library/system.data. datarelation.aspx [ ^ ]
ok..Im not understanding your question pretty well..but I suppose you want to create a relation between the datarow members (a sort of merging multiple rows)..in that case you would need to call the DataRelation and DataColumn classes.

Read the below link and it would give you much insight into it..Its pretty simple and easy :)

http://msdn.microsoft.com/en-us/library/system.data.datarelation.aspx[^]


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

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