如何在XtraGrid的GridView中编辑合并后的单元格
1个回答
展开全部
在默认情况下,GridView 不支持编辑合并后的单元格。本示例主要展示如何创建一个支持编辑合并单元格的自定义GridView。
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Namespace EditMergedCells
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Dim dt As DataTable
dt = New DataTable()
dt.Columns.Add("Column1")
dt.Columns.Add("Column2")
Dim dr As DataRow = dt.NewRow()
dr(0) = "Value1"
dr(1) = "Value2"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value1"
dr(1) = "Value3"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value1"
dr(1) = "Value5"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value4"
dr(1) = "Value5"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value4"
dr(1) = "Value5"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value4"
dr(1) = "Value5"
dt.Rows.Add(dr)
myGridControl1.DataSource = dt
gridControl1.DataSource = dt
End Sub
End Class
End Namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EditMergedCells
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DataTable dt;
dt = new DataTable();
dt.Columns.Add("Column1");
dt.Columns.Add("Column2");
DataRow dr = dt.NewRow();
dr[0] = "Value1";
dr[1] = "Value2";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value1";
dr[1] = "Value3";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value1";
dr[1] = "Value5";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value4";
dr[1] = "Value5";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value4";
dr[1] = "Value5";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value4";
dr[1] = "Value5";
dt.Rows.Add(dr);
myGridControl1.DataSource = dt;
gridControl1.DataSource = dt;
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Namespace EditMergedCells
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Dim dt As DataTable
dt = New DataTable()
dt.Columns.Add("Column1")
dt.Columns.Add("Column2")
Dim dr As DataRow = dt.NewRow()
dr(0) = "Value1"
dr(1) = "Value2"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value1"
dr(1) = "Value3"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value1"
dr(1) = "Value5"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value4"
dr(1) = "Value5"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value4"
dr(1) = "Value5"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "Value4"
dr(1) = "Value5"
dt.Rows.Add(dr)
myGridControl1.DataSource = dt
gridControl1.DataSource = dt
End Sub
End Class
End Namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EditMergedCells
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DataTable dt;
dt = new DataTable();
dt.Columns.Add("Column1");
dt.Columns.Add("Column2");
DataRow dr = dt.NewRow();
dr[0] = "Value1";
dr[1] = "Value2";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value1";
dr[1] = "Value3";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value1";
dr[1] = "Value5";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value4";
dr[1] = "Value5";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value4";
dr[1] = "Value5";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "Value4";
dr[1] = "Value5";
dt.Rows.Add(dr);
myGridControl1.DataSource = dt;
gridControl1.DataSource = dt;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询