2
votes

I am using the LookUpEdit control. I bound two columns, a primary key (GUID) and a human readable string. I only want people to see the human readable string, but I want to preserve the relationship between the string value and it's primary key value.

I can't seem to hide the primary key from displaying on dropdown. I've tried the DevExpress forum and their proposed solution does not work for me. So I tried hooking into the ListChanged event. That is not working either.

private void DataBind()
{
    messageTypeCbB.ListChanged += new ListChangedEventHandler(messageTypeCbB_ListChanged);
    messageTypeCbB.Properties.DataSource = viewModel.SomeNoteTypes.ToArray();
    //another attempt at hiding the columns.  This fails too.  
    //messageTypeCbB.Properties.ForceInitialize();
    //messageTypeCbB.Properties.PopulateColumns();
    //messageTypeCbB.Properties.Columns[0].Visible = false;
    messageTypeCbB.Properties.DisplayMember = "NodeType";
    messageTypeCbB.Properties.ValueMember = "SomeNoteType_ID";

    fromTxt.Text = viewModel.From;
    dateTimeDd.DateTime = viewModel.Date;
}

void messageTypeCbB_ListChanged(object sender, ListChangedEventArgs e)
{            
    //For whatever reason this won't hide the column
    (sender as DevExpress.XtraEditors.LookUpEdit).Properties.Columns[0].Visible = false;
}

How can I hide the surrogate key? (Hide ValueMember display only DisplayMember)

DevExpress v11.1.6

2

2 Answers

0
votes

Have you tried the other method suggested in that forum listing? i.e. not setting Visible to false but rather explicitly adding the columns you want to be displayed to the Columns collection. Try Columns.Clear() then add your column(s). Or try PopulateColumns() then Columns.RemoveAt(0);

0
votes

I was calling DataBind() from my Form constructor. I moved the call into the Form Load event and it solved the problem.