在运行时更改datagridview单元格边框 [英] Changing datagridview cell borders at runtime

查看:114
本文介绍了在运行时更改datagridview单元格边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我希望能够在运行时将某些单元格上的单元格边框改为无框架,以使一组单元格出现合并


我在cellformatting事件中尝试了以下内容......,无济于事


任何想法
<问候

Steve

如果dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.T oString<> ""然后


Dim mystyle As New DataGridViewAdvancedBorderStyle

mystyle.Top = DataGridViewAdvancedCellBorderStyle.None


Dim myplaceholder As New DataGridViewAdvancedBorderStyle

dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).AdjustC ellBorderStyle(mystyle,

myplaceholder,False,False ,假,假)


结束如果

Hi All

I would like to be able to change the cell borders on certain cells to none
at runtime to make a group of cells appear to be merged

I have tried the following in the cellformatting event..., to no avail

Any ideas

Regards
Steve
If dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.T oString <> "" Then

Dim mystyle As New DataGridViewAdvancedBorderStyle

mystyle.Top = DataGridViewAdvancedCellBorderStyle.None

Dim myplaceholder As New DataGridViewAdvancedBorderStyle

dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).AdjustC ellBorderStyle(mystyle,
myplaceholder, False, False, False, False)

End If

推荐答案

史蒂夫,


我从未见过这是可能的。解决方案是在数据表中创建额外的列,其中包含一个连接两个

列的表达式。

http://www.vb-tips.com/ default.aspx?... c-f0b560f43e7c


它是关于一个组合框当然只是一个细节解决方案是

对于任何复杂的数据控制都是一样的。


我希望这会有所帮助,


Cor


"史蒂夫" < GA ***** @ newsgroups.nospam> schreef在bericht

新闻:我们************** @ TK2MSFTNGP04.phx.gbl ...
steve,

I never have seen that this was possible. The solution for this is to create
extra columns in your datatable with an expression which concatenate two
columns.

http://www.vb-tips.com/default.aspx?...c-f0b560f43e7c

That it is about a combobox is of course only a detail the solution is the
same for any complex datacontrol.

I hope this helps,

Cor

"steve" <ga*****@newsgroups.nospam> schreef in bericht
news:us**************@TK2MSFTNGP04.phx.gbl...
大家好
我希望能够在某些单元格上更改单元格边框,以便在运行时不会使一组单元格看起来合并

我试过以下在cellformatting事件......,无济于事

任何想法

关于
史蒂夫
如果dgv1.Rows(e.RowIndex)。细胞(e.ColumnIndex).Value.T oString<> ""然后

将我的样式调暗为新的DataGridViewAdvancedBorderStyle

mystyle.Top = DataGridViewAdvancedCellBorderStyle.None

将myplaceholder变为新的DataGridViewAdvancedBorderStyle

dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).AdjustC ellBorderStyle(mystyle,
myplaceholder,False,False,False,False)

结束如果
Hi All

I would like to be able to change the cell borders on certain cells to
none at runtime to make a group of cells appear to be merged

I have tried the following in the cellformatting event..., to no avail

Any ideas

Regards
Steve
If dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.T oString <> "" Then

Dim mystyle As New DataGridViewAdvancedBorderStyle

mystyle.Top = DataGridViewAdvancedCellBorderStyle.None

Dim myplaceholder As New DataGridViewAdvancedBorderStyle

dgv1.Rows(e.RowIndex).Cells(e.ColumnIndex).AdjustC ellBorderStyle(mystyle,
myplaceholder, False, False, False, False)

End If



你好史蒂夫,


感谢你的帖子!


我试图使用下面的代码片段将所有单元格''左边和

右边框设置为无:

private void Form1_Load(object sender,EventArgs e)

{

DataTable dt = new DataTable();

dt.Columns.Add(" column1",typeof(int));

dt.Columns.Add(" column2",typeof(string));

dt.Columns.Add(" column3",typeof(string)); <对于(int i = 0; i< 20; i ++)

{

DataRow dr = dt.NewRow()
;

dr [" column1"] = i;

dr [" column2"] =" item" + i.ToString();

dr [" column3"] =" column3";

dt.Rows.Add(dr);

}

this.dataGridView1.DataSource = dt;


}


private void button1_Click(object sender,EventArgs e)

$

this.dataGridView1.AdvancedCellBorderStyle.Left =

DataGridViewAdvancedCellBorderStyle.None;

this.dataGridView1.AdvancedCellBorderStyle.Right =

DataGridViewAdvancedCellBorderStyle.None;

}


这对我很有帮助。它具有将

行中的所有单元格合并为单个单元格的效果。它是否满足您的需求?


希望它有所帮助。


祝你好运,

Jeffrey Tan
Microsoft在线社区支持

================================= =================

在回复帖子时,请回复群组通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ==============================

此帖子按原样提供。没有保证,也没有授予任何权利。

Hi Steve,

Thanks for your post!

I have tried to use the code snippet below to set all the cells'' left and
right border to none:
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("column1", typeof(int));
dt.Columns.Add("column2", typeof(string));
dt.Columns.Add("column3", typeof(string));

for (int i = 0; i < 20; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item"+i.ToString ();
dr["column3"] = "column3";
dt.Rows.Add(dr);
}
this.dataGridView1.DataSource = dt;

}

private void button1_Click(object sender, EventArgs e)
{
this.dataGridView1.AdvancedCellBorderStyle.Left =
DataGridViewAdvancedCellBorderStyle.None;
this.dataGridView1.AdvancedCellBorderStyle.Right =
DataGridViewAdvancedCellBorderStyle.None;
}

This works well on my side. It has the effect of merging all the cells in a
row into a single cell. Does it meet your need?

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Jeffrey,


谢谢你们展示这个。请直接告诉我这个,它告诉我,我需要花费更多时间在datagridview上。我不是已经这样做了,

但是我觉得这还不够,我的答案仍然基于

数据网格。


你介意,如果我在我们的

网站上设置你的(有点改动和VB)样本。请告诉我,如果我没关系,那就告诉你,你做了它就像新闻组的贡献者或没有它那样做了b $ b(不是引用微软)。


我会喜欢你的名字,否则看起来我们确实做到了。


当我在VBNet中尝试时,你的样本给了我以下错误(我

下次使用loaddatarow时会更容易创建一个

数据表)。


:-)


Cor


错误1预期结束语句。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 1 14

WindowsApplication1

错误2语法错误。 C:\Documents and Settings \cor\Mijn documenten\Visual

Studio 2005 \Projects\Tests \ WindowsApplication1 \ WindowsApp lication1 \ .Form1.vb

2 1 WindowsApplication1

错误3预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 3 5

WindowsApplication1

错误4预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 4 5

WindowsApplication1

错误5预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 5 5

WindowsApplication1

错误6预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 6 5

WindowsApplication1

错误7语句不能出现在方法体外。 C:\Documents和

设置\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Form1.vb 8 5

WindowsApplication1

错误8语法错误。 C:\Documents and Settings \cor\Mijn documenten\Visual

Studio 2005 \Projects\Tests \ WindowsApplication1 \ WindowsApp lication1 \ .Form1.vb

9 5 WindowsApplication1

错误9预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 10 9

WindowsApplication1

错误10预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 11 9

WindowsApplication1

错误11预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 12 9

WindowsApplication1

错误12预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 13 9

WindowsApplication1

错误13预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 14 9

WindowsApplication1

错误14语法错误。 C:\Documents and Settings \cor\Mijn documenten\Visual

Studio 2005 \Projects\Tests \ WindowsApplication1 \ WindowsApp lication1 \ .Form1.vb

15 5 WindowsApplication1

错误15预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 16 5

WindowsApplication1

错误16语法错误。 C:\Documents and Settings \cor\Mijn documenten\Visual

Studio 2005 \Projects\Tests \ WindowsApplication1 \ WindowsApp lication1 \ .Form1.vb

18 1 WindowsApplication1

错误17预期结束语句。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 20 14

WindowsApplication1

错误18语法错误。 C:\Documents and Settings \cor\Mijn documenten\Visual

Studio 2005 \Projects\Tests \ WindowsApplication1 \ WindowsApp lication1 \ .Form1.vb

21 1 WindowsApplication1

错误19预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 22 5

WindowsApplication1

错误20预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 23 1

WindowsApplication1

错误21预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 24 5

WindowsApplication1

错误22预期声明。 C:\Documents and Settings \cor\Mijn

documenten \ Visual Studio

2005 \Projects\Tests \ WindowsApplication1 \ Windows Form1.vb 25 1

WindowsApplication1

错误23语法错误。 C:\Documents and Settings \cor\Mijn documenten\Visual

Studio 2005 \Projects\Tests \ WindowsApplication1 \ WindowsApp lication1 \ .Form1.vb

26 1 WindowsApplication1


"" Jeffrey Tan [MSFT]"" < JE *** @ online.microsoft.com> schreef in bericht

新闻:NC ************** @ TK2MSFTNGXA01.phx.gbl ...
Jeffrey,

Thank you showing this. Feel free to tell me this direct, it shows me that I
have to take more time in the datagridview. It is not I did that already,
but I see that it is not enough, I base my answers still to much about the
datagrid.

Do you mind, if I set your (a little bit changed and in VB) sample on our
website. Please tell than if that is OK that I than tell that you made it
(not referencing microsoft) just as newsgroup contributer or without that.

I would like it with your name otherwise it looks if we did make that.

Your sample gave me however the errors below when I did try it in VBNet (I
would use next time the loaddatarow, that is much easier to create a
datatable).

:-)

Cor

Error 1 End of statement expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 1 14
WindowsApplication1
Error 2 Syntax error. C:\Documents and Settings\cor\Mijn documenten\Visual
Studio 2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb
2 1 WindowsApplication1
Error 3 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 3 5
WindowsApplication1
Error 4 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 4 5
WindowsApplication1
Error 5 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 5 5
WindowsApplication1
Error 6 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 6 5
WindowsApplication1
Error 7 Statement cannot appear outside of a method body. C:\Documents and
Settings\cor\Mijn documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 8 5
WindowsApplication1
Error 8 Syntax error. C:\Documents and Settings\cor\Mijn documenten\Visual
Studio 2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb
9 5 WindowsApplication1
Error 9 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 10 9
WindowsApplication1
Error 10 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 11 9
WindowsApplication1
Error 11 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 12 9
WindowsApplication1
Error 12 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 13 9
WindowsApplication1
Error 13 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 14 9
WindowsApplication1
Error 14 Syntax error. C:\Documents and Settings\cor\Mijn documenten\Visual
Studio 2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb
15 5 WindowsApplication1
Error 15 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 16 5
WindowsApplication1
Error 16 Syntax error. C:\Documents and Settings\cor\Mijn documenten\Visual
Studio 2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb
18 1 WindowsApplication1
Error 17 End of statement expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 20 14
WindowsApplication1
Error 18 Syntax error. C:\Documents and Settings\cor\Mijn documenten\Visual
Studio 2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb
21 1 WindowsApplication1
Error 19 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 22 5
WindowsApplication1
Error 20 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 23 1
WindowsApplication1
Error 21 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 24 5
WindowsApplication1
Error 22 Declaration expected. C:\Documents and Settings\cor\Mijn
documenten\Visual Studio
2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb 25 1
WindowsApplication1
Error 23 Syntax error. C:\Documents and Settings\cor\Mijn documenten\Visual
Studio 2005\Projects\Tests\WindowsApplication1\WindowsApp lication1\Form1.vb
26 1 WindowsApplication1

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> schreef in bericht
news:NC**************@TK2MSFTNGXA01.phx.gbl...
嗨Steve,

感谢你的帖子!

我试图使用下面的代码片段将所有单元格的'left和
右边框设置为无:
private void Form1_Load(object sender,EventArgs e)
{DataTable dt = new DataTable();
dt.Columns.Add(" column1",typeof(int));
dt.Columns.Add(" column2",typeof(string));
dt.Columns.Add(" column3",typeof(string));

for( int i = 0; i< 20; i ++)
{DataRow dr = dt.NewRow();
dr [" column1"] = i;
dr [ " column2"] =" item" + i.ToString();
dr [" column3"] =" column3";
dt.Rows.Add(dr);
}
this.dataGridView1.DataSource = dt;

}
私有void button1_Click(对象发送者,EventArgs e) {
this.dataGridView1.AdvancedCellBorderStyle.Left =
DataGridViewAdvancedCellBorderStyle.None;
this.dataGridView1.AdvancedCellBorderStyle.Right =
DataGridViewAdvancedCellBorderStyle.None;
}

这对我来说很有效。它具有将所有单元格中的单元格合并为单个单元格的效果。它是否符合您的需求?

希望它有所帮助。

致以最诚挚的问候,
Jeffrey Tan
Microsoft在线社区支持
=== ===============================================
在回复帖子时,请回复群组通过您的新闻阅读器,以便其他人可以从您的问题中学习并从中受益。
============================ ======================
此帖子是原样提供的。没有保证,也没有赋予
权利。
Hi Steve,

Thanks for your post!

I have tried to use the code snippet below to set all the cells'' left and
right border to none:
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("column1", typeof(int));
dt.Columns.Add("column2", typeof(string));
dt.Columns.Add("column3", typeof(string));

for (int i = 0; i < 20; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item"+i.ToString ();
dr["column3"] = "column3";
dt.Rows.Add(dr);
}
this.dataGridView1.DataSource = dt;

}

private void button1_Click(object sender, EventArgs e)
{
this.dataGridView1.AdvancedCellBorderStyle.Left =
DataGridViewAdvancedCellBorderStyle.None;
this.dataGridView1.AdvancedCellBorderStyle.Right =
DataGridViewAdvancedCellBorderStyle.None;
}

This works well on my side. It has the effect of merging all the cells in
a
row into a single cell. Does it meet your need?

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.



这篇关于在运行时更改datagridview单元格边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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