找回密码
 立即注册

QQ登录

只需一步,快速开始

sunyuanze

注册会员

21

主题

66

帖子

169

积分

注册会员

积分
169

活字格认证微信认证勋章

sunyuanze
注册会员   /  发表于:2014-10-1 12:29  /   查看:6662  /  回复:5


我们现在需要使用FlexGrid的Excel文件读入功能。

现在的问题是,正常读入数据和设置的颜色等都没问题,
但是读入以后,需要设置某些列为下拉框就有问题了。

问题一:例如我只设置了第3列和第8列的DataMap,但是其他没有设置DataMap 的列也会变成下拉框。
问题二:下拉框选择值后,选择的内容text并没有设置到单元格上,而是设置成了value值。

例子代码见附件。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

5 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2014-10-8 16:46:00
沙发
回复 1楼sunyuanze的帖子

请问你是什么版本VisualStudio,程序打不开。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
sunyuanze
注册会员   /  发表于:2014-10-8 18:18:00
板凳
2012的。

你要是没有,就在你的版本上随便建个form,把下面代码粘进去应该就行。
using C1.Win.C1FlexGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.flxGrid.LoadExcel("C:/test_data.xlsx", FileFlags.AsDisplayed | FileFlags.IncludeFixedCells | FileFlags.IncludeMergedRanges);

            var dic1 = new Dictionary<int, string>();
            dic1.Add(0, "a");
            dic1.Add(1, "b");
            dic1.Add(2, "c");

            var dic2 = new Dictionary<int, string>();
            dic2.Add(0, "A");
            dic2.Add(1, "B");
            dic2.Add(2, "C");

            for (int row = 2; row < this.flxGrid.Rows.Count; row++)
            {
                this.flxGrid.GetCellStyle(row, 3).DataMap = dic1;
                this.flxGrid.GetCellStyle(row, 8).DataMap = dic2;
            }

            CellStyle cs;
            this.flxGrid.SelectionMode = SelectionModeEnum.Row;
            this.flxGrid.HighLight = HighLightEnum.WithFocus;
            this.flxGrid.Rows.Fixed = 2;
            this.flxGrid.Cols.Frozen = 5;
            this.flxGrid.Rows[0].AllowMerging = true;
            this.flxGrid.Rows[1].AllowMerging = true;
            this.flxGrid.Cols.Count = 10;
            this.flxGrid.Cols.Fixed = 0;

            cs = this.flxGrid.Styles.SelectedColumnHeader;
            cs.Border.Color = Color.FromArgb(53, 56, 56);
            cs.BackColor = Color.FromArgb(70, 77, 87);
            cs.ForeColor = Color.White;
            cs.Font = new Font("Meiryo UI", 12, FontStyle.Regular);
            cs.TextAlign = TextAlignEnum.CenterCenter;

            for (int row = 0; row < this.flxGrid.Rows.Count; row++)
            {
                this.flxGrid.Rows[row].Height = 25;
            }

            
        }
    }
}
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-10-9 14:37:00
地板
回复 3楼sunyuanze的帖子

测试代码:
  1.             this.c1FlexGrid1.LoadExcel(@"D:\test_data.xlsx", FileFlags.AsDisplayed | FileFlags.IncludeFixedCells | FileFlags.IncludeMergedRanges);

  2.             var dic1 = new Dictionary<int, string>();
  3.             dic1.Add(0, "a");
  4.             dic1.Add(1, "b");
  5.             dic1.Add(2, "c");

  6.             var dic2 = new Dictionary<int, string>();
  7.             dic2.Add(0, "A");
  8.             dic2.Add(1, "B");
  9.             dic2.Add(2, "C");

  10.             CellStyle cs = this.c1FlexGrid1.Styles.Add("dic1");
  11.             cs.DataType = typeof(int);
  12.             cs.DataMap = dic1;

  13.             CellStyle cs2 = this.c1FlexGrid1.Styles.Add("dic2");
  14.             cs2.DataType = typeof(int);
  15.             cs2.DataMap = dic2;

  16.             for (int row = 2; row < this.c1FlexGrid1.Rows.Count; row++)
  17.             {
  18.                 this.c1FlexGrid1.SetCellStyle(row, 3, cs);
  19.                 this.c1FlexGrid1.SetCellStyle(row, 8, cs2);

  20.             }
复制代码


这样子测试能够正常显示。有可能因为Cell使用的CellStyle是一样的,你对CellStyle进行更改的时候,所有应用这个CellStyle的单元格都使用你的CellStyle。所以我创建了个新的CellStyle。

评分

参与人数 1满意度 +5 收起 理由
sunyuanze + 5 回答满意

查看全部评分

请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
sunyuanze
注册会员   /  发表于:2014-10-15 10:10:00
5#
回复 4楼Alice的帖子

恩,可能就是这个原因,多谢回答:)
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-10-15 14:34:00
6#
回复 5楼sunyuanze的帖子

不用客气。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部