开发者

How to display values in list view

开发者 https://www.devze.com 2023-03-22 04:14 出处:网络
I have code like this if(Data.ResourcePolicy == null) SubItem开发者_开发知识库s.Add(ResourcePolicyAvailSystemsLVI.m_nullString);

I have code like this

 if(Data.ResourcePolicy == null)
                SubItem开发者_开发知识库s.Add(ResourcePolicyAvailSystemsLVI.m_nullString);
             else
                SubItems.Add(Data.ResourcePolicy.Name);

             if (Data.AgentVersion == null || Data.AgentVersion.Equals("0.0.0.0"))
                SubItems.Add(ResourcePolicySystemsControl.m_nullVersion);
             else
                SubItems.Add(Data.AgentVersion);
             SubItems.Add(Data.AgentState.ToString());

i need to display ResourcePolicyAvailSystemsLVI.m_nullString only if Data.ResourcePolicy == null, if (Data.ResourcePolicy == null) and Data.AgentVersion != null then i should display ResourcePolicyAvailSystemsLVI.unknown How will i achieve this,


If this what you mean?

bool isNullVersion=(Data.AgentVersion ?? "0.0.0.0") == "0.0.0.0";
string policy= isNullVersion ? 
                           ResourcePolicyAvailSystemsLVI.m_nullString :
                           ResourcePolicyAvailSystemsLVI.unknown;
if (Data.ResourcePolicy !=null) policy=Data.ResourcePolicy.Name;
SubItems.Add(policy);
SubItems.Add(isNullVersion ? 
                            ResourcePolicySystemsControl.m_nullVersion :
                            Data.AgentVersion
            );
SubItems.Add(Data.AgentState.ToString());


Extent the class of Data:

public class DataClass
{
    //....

    public string ResourcePolicyName
    {
        get { return ResourcePolicy != null ? ResourcePolicy.Name : ResourcePolicyAvailSystemsLVI.m_nullString; }
    }

    public string AgentVersionString
    {
        get
        {
            if (AgentVersion == null || AgentVersion.Equals("0.0.0.0"))
            {
                return ResourcePolicySystemsControl.m_nullVersion;
            }
            return AgentVersion;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消