删除Datagrid列 [英] Deleting a Datagrid column

查看:69
本文介绍了删除Datagrid列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


请原谅我的无知,因为我很确定这很容易做到。我有一个datagrid

,我想让用户删除列。我在具有删除选项的

数据网格中添加了一个上下文菜单。如果用户右键单击列

标题,我可以突出显示该列然后将其删除吗?我不太确定

如何突出显示它或找出被点击的列。


在我的测试中到目前为止我使用上下文菜单我总是得到错误

列''ColumnName''确实属于表'" - 我正在尝试删除第一个

列:


((DataTable)dgdData.DataSource).Columns.RemoveAt(0);


当我添加一个按钮并使用相同的代码行时,我没有收到错误

并删除了该列。有什么想法吗?


感谢您的帮助,我真的很感激。


谢谢,

Nick

Hello,

Please pardon my ignorance as I''m sure this is easy to do. I have a datagrid
where I want to let the user delete columns. I added a context menu to the
datagrid that has a delete option. If the user right clicks on a column
heading can I highlight that column and then delete it? I''m not exactly sure
how to highlight it or figure out what column has been clicked.

In my testing so far when I use the context menu I always get the error
"Column ''ColumnName'' does belong to table" - I''m trying to remove the first
column:

((DataTable)dgdData.DataSource).Columns.RemoveAt(0 );

When I added a button and use the same line of code I do not get the error
and the column is removed. Any ideas why?

Thanks for any help, I really appreciate it.

Thanks,
Nick

推荐答案

我认为你不应该删除列。

而是使用一个显示数据列的视图表。那么,你可以简单地用
来改变显示的colums。

那样te列留在它们的位置,但它们只是没有显示。


亲切的问候,

Bruno。

" Nick" < NI ******** @ nospam.nospam>在消息中写道

news:46 ********************************** @ microsof t.com ...
I don''t think you should delete columns.
instead, use a view that shows colums of a data table. then, you can simply
change the colums that are shown.
that way te columns stay where they are, but they are just not shown.

kind regards,
Bruno.
"Nick" <ni********@nospam.nospam> wrote in message
news:46**********************************@microsof t.com...
你好,

请原谅我的无知,因为我很确定这很容易做到。我有一个
datagrid
我想让用户删除列。我在
数据网格中添加了一个上下文菜单,其中包含一个删除选项。如果用户右键单击一个列
标题,我可以突出显示该列然后将其删除吗?我不完全确定
如何突出显示它或找出被点击的列。

在我的测试中到目前为止,当我使用上下文菜单时,我总是得到错误
列''ColumnName''确实属于表'' - 我正在尝试删除
第一栏:

((DataTable)dgdData.DataSource).Columns.RemoveAt(0);
并删除了该列。任何想法为什么?

感谢您的帮助,我真的很感激。

谢谢,
Nick
Hello,

Please pardon my ignorance as I''m sure this is easy to do. I have a
datagrid
where I want to let the user delete columns. I added a context menu to the
datagrid that has a delete option. If the user right clicks on a column
heading can I highlight that column and then delete it? I''m not exactly
sure
how to highlight it or figure out what column has been clicked.

In my testing so far when I use the context menu I always get the error
"Column ''ColumnName'' does belong to table" - I''m trying to remove the
first
column:

((DataTable)dgdData.DataSource).Columns.RemoveAt(0 );

When I added a button and use the same line of code I do not get the error
and the column is removed. Any ideas why?

Thanks for any help, I really appreciate it.

Thanks,
Nick



布鲁诺,


感谢您的帮助。我实际上没有将数据库记录加载到

数据网格中。它们是我从文本文件中提取的价值观。我想允许

他们对数据做任何他们想做的事情然后我会把它保存回

文件。


谢谢,

尼克


" Bruno van Dooren"写道:
Bruno,

Thanks for your help. I''m actually not loading database records into the
datagrid. They are values I''m pulling in from a text file. I want to allow
them to do whatever they want to the data and then I will save it back to the
file.

Thanks,
Nick

"Bruno van Dooren" wrote:
我认为你不应该删除列。
而是使用一个显示数据表列的视图。那么,你可以简单地改变所显示的colums。
te列保持原样,但它们只是没有显示。

亲切的问候,布鲁诺。

尼克 < NI ******** @ nospam.nospam>在消息中写道
新闻:46 ********************************** @ microsof t.com。 ..
I don''t think you should delete columns.
instead, use a view that shows colums of a data table. then, you can simply
change the colums that are shown.
that way te columns stay where they are, but they are just not shown.

kind regards,
Bruno.
"Nick" <ni********@nospam.nospam> wrote in message
news:46**********************************@microsof t.com...
你好,

请原谅我的无知,因为我很确定这很容易做到。我有一个
datagrid
我想让用户删除列。我在
数据网格中添加了一个上下文菜单,其中包含一个删除选项。如果用户右键单击一个列
标题,我可以突出显示该列然后将其删除吗?我不完全确定
如何突出显示它或找出被点击的列。

在我的测试中到目前为止,当我使用上下文菜单时,我总是得到错误
列''ColumnName''确实属于表'' - 我正在尝试删除
第一栏:

((DataTable)dgdData.DataSource).Columns.RemoveAt(0);
并删除了该列。任何想法为什么?

感谢您的帮助,我真的很感激。

谢谢,
Nick
Hello,

Please pardon my ignorance as I''m sure this is easy to do. I have a
datagrid
where I want to let the user delete columns. I added a context menu to the
datagrid that has a delete option. If the user right clicks on a column
heading can I highlight that column and then delete it? I''m not exactly
sure
how to highlight it or figure out what column has been clicked.

In my testing so far when I use the context menu I always get the error
"Column ''ColumnName'' does belong to table" - I''m trying to remove the
first
column:

((DataTable)dgdData.DataSource).Columns.RemoveAt(0 );

When I added a button and use the same line of code I do not get the error
and the column is removed. Any ideas why?

Thanks for any help, I really appreciate it.

Thanks,
Nick




无论如何,你可以将文本文件中的数据加载到数据表中,然后按照我的建议行。$ / b $ b $

你可以从各种数据源填写数据表。


亲切的问候,

Bruno。

" Nick" ; < NI ******** @ nospam.nospam>在消息中写道

news:46 ********************************** @ microsof t.com ...
regardless, you can load the data from the text file into a data table and
then do what i suggested.
you can fill data tables from all sorts of data sources.

kind regards,
Bruno.
"Nick" <ni********@nospam.nospam> wrote in message
news:46**********************************@microsof t.com...
布鲁诺,

感谢您的帮助。我实际上没有将数据库记录加载到
数据网格中。它们是我从文本文件中提取的价值观。我想允许他们对数据做任何他们想做的事情然后我会把它保存回




谢谢,
Nick

Bruno van Dooren写道:
Bruno,

Thanks for your help. I''m actually not loading database records into the
datagrid. They are values I''m pulling in from a text file. I want to allow
them to do whatever they want to the data and then I will save it back to
the
file.

Thanks,
Nick

"Bruno van Dooren" wrote:
我认为你不应该删除列。
而是使用一个显示数据表列的视图。然后,你可以简单地
更改显示的colums。
te列保持原样,但它们只是没有显示。

亲切的问候,Bruno。

" Nick" < NI ******** @ nospam.nospam>在消息中写道
新闻:46 ********************************** @ microsof t.com。 ..
I don''t think you should delete columns.
instead, use a view that shows colums of a data table. then, you can
simply
change the colums that are shown.
that way te columns stay where they are, but they are just not shown.

kind regards,
Bruno.
"Nick" <ni********@nospam.nospam> wrote in message
news:46**********************************@microsof t.com...
>你好,
>
>请原谅我的无知,因为我确信这很容易做到。我有一个
> datagrid
>我想让用户删除列的位置。我添加了一个上下文菜单到
>
>具有删除选项的datagrid。如果用户右键单击列
>标题我可以突出显示该列,然后将其删除吗?我不完全是
>确定
>如何突出显示或找出已点击的列。
>
>在我使用上下文菜单的测试中,我总是得到错误
> 列''ColumnName''确实属于表 - 我正在尝试删除
>第一个
>专栏:
>
> ((DataTable)dgdData.DataSource).Columns.RemoveAt(0);
>
>当我添加一个按钮并使用相同的代码行时,我没有得到
>错误
>并删除该列。任何想法为什么?
>
>感谢您的帮助,我真的很感激。
>
>谢谢,
>尼克
> Hello,
>
> Please pardon my ignorance as I''m sure this is easy to do. I have a
> datagrid
> where I want to let the user delete columns. I added a context menu to
> the
> datagrid that has a delete option. If the user right clicks on a column
> heading can I highlight that column and then delete it? I''m not exactly
> sure
> how to highlight it or figure out what column has been clicked.
>
> In my testing so far when I use the context menu I always get the error
> "Column ''ColumnName'' does belong to table" - I''m trying to remove the
> first
> column:
>
> ((DataTable)dgdData.DataSource).Columns.RemoveAt(0 );
>
> When I added a button and use the same line of code I do not get the
> error
> and the column is removed. Any ideas why?
>
> Thanks for any help, I really appreciate it.
>
> Thanks,
> Nick




这篇关于删除Datagrid列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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