是否有可能创建一个DataGridView它看起来像这样? [英] Is it possible to create a DataGridView which looks like this?

查看:130
本文介绍了是否有可能创建一个DataGridView它看起来像这样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此已经开发了通过使用一些第三方组分如C1中。正如你可以看到有三种这里排...

This have been developed by using some third party component such as C1. As you can see there are are three kinds of rows here...

类型1. L0000000000000000420 - 这种行是从数据库中获取。 (只读)

Type 1. L0000000000000000420 - this kind of row is fetched from database. (Read Only)

键入2.输入金额 - 这种行是为用户输入量。 (这其中也可能包含一些列跌幅downlist)(编辑只有最好的时候)

Type 2. Enter Amount - this kind of row is for the user to input amount. (this one might also contain drop downlist in some columns) (Editable only when Checked)

键入3 WHITE行 - 这仅仅是一个空白的只读排了更好的外观和感觉。

Type 3. WHITE ROW- this is just a blank Read Only row for better look and feel.

我想知道的是它可以创建类似的,如果不是完全不使用任何第三方组件的同一种DataGridView的吗? 我的想法是......来从数据库中的行成一个数据表,然后循环它...我想,已经被抓走,每一行后面添加DataTable中的两个额外的空白行。

I want to know is it possible to create similar if not exactly the same kind of DataGridView without using any third party component? My idea is .. to fetch the rows from database into a DataTable and then loop it ... I am thinking of adding two extra blank rows in the DataTable after each row that has been fetched.

我也将增加,这将有一个值的列,例如,

I will also add a column which will have a value such as ,

A - (这是为了表明1型)

A - (this is to indicate type 1)

乙 - (这是为了表示2型)

B - (this is to indicate type 2)

Ç - (这是为了表示式3)

C - (this is to indicate type 3)

A

B

C.。等

我会再检查排在一个循环的类型和该行然后设置属性为相应的只读/编辑,颜色属性。

I will then check the type of row in a loop and then set property of that row to read only/ editable , color properties accordingly.

但我不知道这是实际可行的。我不是不知道我要怎么加入组合框仅供TPE 2列。因为如果我添加一个组合框栏将显示在所有三排。这可能吗?如果是的话,你能不能给我一些想法如何?我需要知道我可以做到这一点问一些更具体的问题之前,我。谢谢你。

But I am not sure if this is practically possible. I am not not sure how am i gonna add ComboBox for only tpe 2 column. Because if I add a ComboBox column it will be displayed in all three rows. Is this possible? If yes, can you give me some idea how? I need to know how I can do this before I ask some more specific questions. Thank You.

推荐答案

我会同意,WPF更好/更快地为这几样东西,但它是他的选择是否使用与否。并从头开始学习WPF是不是快...

I may agree that WPF is better/faster for these kind of things, but it's his choice whether to use it or not. And learning WPF from scratch is NOT that fast...

只要手动将数据绑定到你的的DataGridView 您可以控制​​的行为,并期待您的单细胞,当然也包括的颜色(这是最容易的部分)。我包括为消失组合框单元的一个例子。最后一列是一个简单的 DataGridViewComboBoxColumn

As long as manually bind your data to your DataGridView you can control the behavior and look of your single cells, including of course the color (that's the easiest part). I include an example for the "disappearing combobox" cell. The last column is a simple DataGridViewComboBoxColumn.

private void Form1_Load(object sender, EventArgs e)
{

    dataGridView1.Rows.Add(new[] { "L00000422", "", "","A" });
    dataGridView1.Rows.Add(new[] { "Enter Amount", "", "","" });
    dataGridView1.Rows.Add(new[] { "", "", "","" });
    dataGridView1.Rows.Add(new[] { "L00000423", "", "" ,"B"});
    dataGridView1.Rows.Add(new[] { "Enter Amount", "", "", "" });
    dataGridView1.Rows.Add(new[] { "", "", "", "" });

    foreach (var row in dataGridView1.Rows)
    {
        var r = (DataGridViewRow) row;
        foreach (var col in dataGridView1.Columns)
        {
            var cl = (DataGridViewColumn) col;
            if (cl.Index == 3)
            {
                var cc = (DataGridViewComboBoxCell)dataGridView1[3,r.Index];
                if (r.Index % 3 != 0)
                {
                    cc.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                    cc.ReadOnly = true;
                }
                else
                {
                    cc.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
                    cc.ReadOnly = false;
                }
            }
        }
    }
}

这篇关于是否有可能创建一个DataGridView它看起来像这样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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