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

时间:2013-04-30 22:11:15

标签: c# datagridview contextmenu

我有一个DataGridView有两种类型的单元格,不同的是背景色(红色/绿色)。 我想为这个DataGridView设置一个ContextMenu,但我希望红色单元格和绿色单元格不同。有没有办法这样做?

作为第二个问题,有没有办法为ToolTip分配DataGridViewCells,并且再次与红色/绿色单元格不同?

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

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>