spread 15.0 SheetView绑定Models.Data = model后,designer中设置的列标题失效
winform spread 15.0 SheetView绑定Models.Data = model后,designer中设置的列标题失效这个是静态画面
执行完spread_Sheet1.Models.Data = model;
designer.cs文件中对表格的属性设置全被清空,有什么好的解决办法吗?
列标题没有了
主画面
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private MTGA0010MeisaiSheetDataModel model;
/// <summary>
///
/// </summary>
List<DataRow> hanyoKanriRecordDetail;
public DataTable HanyoKanriRecordDetail
{
set
{
hanyoKanriRecordDetail = new List<DataRow>();
if (value != null)
{
hanyoKanriRecordDetail.AddRange(value.AsEnumerable().ToList());
}
//RefreshList();
}
}
public Form1()
{
model = new MTGA0010MeisaiSheetDataModel();
//model = new FarPoint.Win.Spread.Model();
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// SPREAD初期化处理
spread_Sheet1.Models.Data = model;
}
}
}
MTGA0010MeisaiSheetDataModel.cs
namespace MTGA0010.DataModel
{
/// <summary>
/// SPREAD SheetDataModel
/// </summary>
public class MTGA0010MeisaiSheetDataModel : BaseSheetDataModel
{
/// <summary>
///
/// </summary>
List<DataRow> hanyoKanriRecordDetail;
/// <summary>
///
/// </summary>
private bool readOnly;
/// <summary>
///
/// </summary>
private List<Func<int, object>> columns = new List<Func<int, object>>();
/// <summary>
///
/// </summary>
public bool ReadOnly
{
get { return readOnly; }
set
{
readOnly = value;
if (hanyoKanriRecordDetail != null)
{
RefreshList();
}
}
}
/// <summary>
///
/// </summary>
public void RefreshList()
{
OnChanged(new SheetDataModelEventArgs(-1, -1,
this.RowCount, this.ColumnCount, SheetDataModelEventType.ModelUpdated));
}
/// <summary>
///
/// </summary>
public DataTable HanyoKanriRecordDetail
{
set
{
hanyoKanriRecordDetail = new List<DataRow>();
if (value != null)
{
hanyoKanriRecordDetail.AddRange(value.AsEnumerable().ToList());
}
RefreshList();
}
}
/// <summary>
///
/// </summary>
public MTGA0010MeisaiSheetDataModel()
{
this.hanyoKanriRecordDetail = null;
this.hanyoKanriRecordDetail = new List<DataRow>();
SetColumn();
}
/// <summary>
///
/// </summary>
public override int RowCount
{
get
{
if (hanyoKanriRecordDetail == null)
{
return 0;
}
return this.hanyoKanriRecordDetail.Count;
}
}
/// <summary>
///
/// </summary>
public override int ColumnCount
{
get
{
return columns.Count;
}
}
/// <summary>
///
/// </summary>
private void SetColumn()
{
Func<int, Class1> f = r => new Class1(hanyoKanriRecordDetail);
columns.Add((r) => f(r).GetString("HAK_KANRI_KBN"));
columns.Add((r) => f(r).GetString("HAK_MEISAI_KBN"));
columns.Add((r) => f(r).GetString("HAK_MEISAI_NM"));
columns.Add((r) => f(r).GetDate("HAK_INSERT_DATE"));
columns.Add((r) => f(r).GetString("HAK_INSERT_USER"));
columns.Add((r) => f(r).GetDate("HAK_UPDATE_DATE"));
columns.Add((r) => f(r).GetString("HAK_UPDATE_USER"));
}
/// <summary>
///
/// </summary>
public void SetDetailData()
{
RefreshList();
}
/// <summary>
///
/// </summary>
/// <param name="rowNumber"></param>
/// <returns></returns>
public DataRow GetDetailRow(int rowNumber)
{
return hanyoKanriRecordDetail;
}
/// <summary>
///
/// </summary>
/// <param name="row"></param>
public void AddDetailData(DataRow row)
{
hanyoKanriRecordDetail.Add(row);
RefreshList();
}
/// <summary>
///
///
/// </summary>
/// <param name="row"></param>
/// <param name="column"></param>
/// <returns></returns>
public override object GetValue(int row, int column)
{
object fieldData = "";
fieldData = columns(row);
return fieldData;
}
/// <summary>
///
/// </summary>
/// <param name="row"></param>
/// <param name="column"></param>
/// <param name="value"></param>
public override void SetValue(int row, int column, object value)
{
base.SetValue(row, column, value);
switch (column)
{
case 0:
DataRow dr = hanyoKanriRecordDetail;
dr["UPDATE_STATUS"] = (bool)value ? 3 : 2;
break;
}
}
}
}
你设置Models.Data = model的目的是什么,是想要实现什么需求呢 Richard.Ma 发表于 2022-11-1 14:14
你设置Models.Data = model的目的是什么,是想要实现什么需求呢
绑定数据源,在数据特别多的情况下,这种绑定方式可以大大提高效率,比datasource快很多 本帖最后由 Richard.Ma 于 2022-11-3 13:24 编辑
验证了一下,目前没有办法同时支持,没有其他办法 本帖最后由 瑞雪 于 2023-2-1 10:53 编辑
Richard.Ma 发表于 2022-11-1 18:00
验证了一下,目前没有办法同时支持,没有其他办法
你好,我们这个是升级项目,在Spread5.0中SheetView绑定Models.Data = model后,mode是继承了BaseSheetDataModel的, designer中的所有设置是有效的,是不是Spread升级后需要设置啥属性才能保留designer中的样式呢 目前没有这方面的资料了,应该是新版本功能更已经发生了变化。
关于datamodel的介绍,你可以参考文档
https://www.grapecity.com/spreadnet/docs/online-win/spwin-model-datastuff.html
另一个建议的尝试是,可以在设置了Models.Data后,重新去通过代码设置列头文字
页:
[1]