Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 881597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:17:19+00:00 2026-05-15T12:17:19+00:00

I’ve posted a similar problem here and wasn’t able to successfully implement the solution

  • 0

I’ve posted a similar problem here and wasn’t able to successfully implement the solution suggested to me as it wasn’t working.I’ve found a way round and wanted to improve it by binding the combobox to a custom objects to enable data validation.here is the xaml for this one

<Window xmlns:data="clr-namespace:Myproject">

<Window.Resources>
  <data:UserLogin x:Key="user"></data:UserLogin>
  <DataTemplate x:Key="comboTemplate">
        <TextBlock Text="{Binding Path=username}" />
  </DataTemplate>
</Window.Resources>
<ComboBox Margin="18,121,24,0" Name="cmbEmail" Tag="email" TabIndex="1" ToolTip="enter the email you signed up with here" IsEditable="True" IsSynchronizedWithCurrentItem="True" ItemTemplate="{StaticResource comboTemplate}"  ItemsSource="{Binding}" Height="23" VerticalAlignment="Top" Style="{DynamicResource cmbBoxerrors}">
            <ComboBox.Text>
                <Binding Path="Loginname" Source="{StaticResource user}" ValidatesOnDataErrors="True" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <ExceptionValidationRule/>
                    </Binding.ValidationRules>
                </Binding>
            </ComboBox.Text>       
 </ComboBox>
</Window>

and the xaml.cs is

           if (con != null)
            {
                if (con.State == ConnectionState.Closed)
                    con.Open();

                SqlCeCommand cmdusers = new SqlCeCommand("select * from users order by id", con);

                SqlCeDataAdapter da = new SqlCeDataAdapter(cmdusers);
                userdt = new DataTable("users");
                da.Fill(userdt);

                cmbEmail.DataContext = userdt;

             }  

and the UserLogin Class is

 class UserLogin :IDataErrorInfo
{
    private string _loginname = "";
    private string _password;


    public string this[string columnName]
    {
        get 
        {  


            string result = null;
            if(columnName == "Loginname")
            {
                if(string.IsNullOrEmpty(this._loginname))
                {
                    result = "Login Name cannot be Empty";
                }
            }

            if (columnName == "Loginname")
            {
                if(!Util.ValidateRegexPatern(Properties.Resources.emailRegex,this._loginname))
                {
                    result = "MalFormed Email address. Please write a correct email addess";
                }
            }

            return result;
        }
    }

    public string Error
    {
        get { return null; }
    }

    public string Password
    {
        get { return _password; }
        set { _password = value; }
    }

    public string Loginname
    {
        get { return _loginname; }
        set { _loginname = value; }
    }
}

the problem is when i use ItemTemplate the selected item shows System.Data.DataRowView but dropdown list items show correctly and when i swap the ItemTemplate with DisplayMemberPath it’s the opposite behavior as in selected items is correct and dropdown list items show System.Data.DataRowView.using them both throws an exception as i can’t use them both selected and dropdown list items show correctly.

I don’t really know what i’m not doing correctly.Can anyone shed some light on this i’ll be verry thankfull.Thanks for reading this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:17:20+00:00Added an answer on May 15, 2026 at 12:17 pm

    It goes like this: you set the data context of the ComboBox to an instance of type DataTable. Then you set the ItemsSource to {Binding} which means each item in the ComboBox will bind to a DataRow (which doesn’t have either loginname, nor username as properties). And here the binding stops working. There’s no implicit way to convert from a DataRow to a UserLogin.

    You ca either implement a converter to do the conversion or convert the rows to UserLogin one by one and set the DataContext of the ComboBox to the list of UserLogin (or an ObservableCollection if you need more advanced functionality).

    In either case drop the <ComboBox.Text> ... </ComboBox.Text> part.

    Hope this helps you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 436k
  • Answers 436k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Please use JavaScript for this: ImagePreview.Attributes.Item("onMouseOver") = "javascript:window.open('localhost','newWindow','width=200,height=200')"; May 15, 2026 at 4:03 pm
  • Editorial Team
    Editorial Team added an answer When using JAXB outside of a JAX-WS environment a JAXB… May 15, 2026 at 4:03 pm
  • Editorial Team
    Editorial Team added an answer You didn't mention your data type of column in your… May 15, 2026 at 4:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.