Labels.VisibilityExpression

Hello.
I have a problem with Labels.VisibilityExpression. the expression with the shapefile works, but with the labels dosn`t work, any idea?
Thanks
My code.

Private Sub CheckedNode_CollectionChanged(sender As Object, e As System.Collections.Specialized.NotifyCollectionChangedEventArgs)
Dim query As String = “”
ShapeMarcasIncidencia.DefaultDrawingOptions.Visible = True
ShapeMarcasIncidencia.Labels.Visible = True
For x = 0 To checkedNode.Count - 1
If checkedNode.Item(x).Tag IsNot Nothing Then
If x = 0 Then
query = "[MWShapeID] = " + checkedNode.Item(x).Tag.ToString + “”
Else
query += " OR [MWShapeID] = " + checkedNode.Item(x).Tag.ToString + “”
End If
End If
Next
If checkedNode.Count = 0 Then
ShapeMarcasIncidencia.DefaultDrawingOptions.Visible = False
ShapeMarcasIncidencia.Labels.Visible = False
Else
ShapeMarcasIncidencia.VisibilityExpression = query
ShapeMarcasIncidencia.Labels.VisibilityExpression = query
End If
AxMap1.Redraw()
End Sub

What is the value of query?

I haven’t used this myself, but looking at the documentation: Labels.VisibilityExpression it should work.

Hello @pmeems the value of query is:


With the shape works but with the labels dosen`t work
this my code for add the labels and shapes.

Thanks for your time.

Hello @Luis

It looks like your last parameter to the AddLabel method is incorrect.

The last parameter should specify the Label Category index, not the Shape or Label index. Since you are not using label categories, you should just let that default to -1.

Regards,
Jerry.

Hello @jerryfaust
Thanks i only was trying,
But with -1 is the same result, i don’t know why.
I can`t apply the visibility expression at labels, but in the shapes works very well.
Regards.
Thanks for your help.

I did this, added the information the label in a column of the table, idon’t know it’s OK, but works.

        ShapeMarcasIncidencia.VisibilityExpression = query
        ShapeMarcasIncidencia.Labels.Clear()
        ShapeMarcasIncidencia.Labels.VisibilityExpression = query
        ShapeMarcasIncidencia.Labels.Generate("[Label]", tkLabelPositioning.lpCenter, True)

Very good. That’s the ideal solution, and the more traditional way you would add shape-based labels.

Rather than adding what might be considered ad-hoc labels, the Generate command creates labels specifically associated with each shape. In this case, I don’t think you need the “Labels.VisibilityExpression”, since the Label visibility should now follow the Shape visibility.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.