删除Datagrid列

编程入门 行业动态 更新时间:2024-10-26 14:33:13
本文介绍了删除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 ... 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... 你好, 请原谅我的无知,因为我很确定这很容易做到。我有一个 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。 .. 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... 你好, 请原谅我的无知,因为我很确定这很容易做到。我有一个 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 ... 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... 布鲁诺, 感谢您的帮助。我实际上没有将数据库记录加载到数据网格中。它们是我从文本文件中提取的价值观。我想允许他们对数据做任何他们想做的事情然后我会把它保存回 谢谢, 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。 .. 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... >你好,> >请原谅我的无知,因为我确信这很容易做到。我有一个> 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列

本文发布于:2023-10-17 02:58:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1499573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Datagrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!