如何为DataGridView中的不同单元格设置不同的ContextMenu

本文关键字:单元格 设置 ContextMenu DataGridView | 更新日期: 2023-09-27 18:11:30

我有一个DataGridView与两种类型的细胞,不同的背景颜色(红色/绿色)。我想为这个DataGridView设置一个ContextMenu,但我希望它对红色细胞和绿色细胞是不同的。有办法做到吗?

作为第二个问题,是否有一种方法为DataGridViewCells分配ToolTip,并且再次与红/绿细胞不同?

如何为DataGridView中的不同单元格设置不同的ContextMenu

解决后,我注意到我不仅可以在DataGridView属性中添加ContextMenuStrip,而且当我使用foreach row到达确切的单元格时,然后在row中使用foreach cell并将ContextMenuStrip设置为确切的单元格。

在网格视图中添加工具提示-

asp:TemplateField HeaderText="Comments" SortExpression="short_comment">
     <ItemTemplate>
         <asp:Label ID="Label1" runat="server" Text='<%# Bind("short_comment") %>' ToolTip ='<%# Bind("longer_comment") %>'></asp:Label>
     </ItemTemplate>
</asp:TemplateField>