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

  • SEARCH
  • Home
  • 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 8729443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:50:04+00:00 2026-06-13T08:50:04+00:00

I have this code: typeof(ComboBox).GetProperty(SelectedItem).SetValue(comboBox1, , null); It is not working. Here is the

  • 0

I have this code:

typeof(ComboBox).GetProperty("SelectedItem").SetValue("comboBox1", "", null);

It is not working. Here is the error:

“Object does not match target type”

What is wrong?

Update:

I have the name of my object (comboBox in string. like:

string []s = new s[3];
s[0]="comboBox0"; 
s[1]="comboBox1"; 
s[2]="comboBox2"; 

I want to set a value to the property SelectedItem to my comboBox s[i]. How can I do it?

  • 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-06-13T08:50:05+00:00Added an answer on June 13, 2026 at 8:50 am

    SetValue need to have ComboBox object, not string “comboBox1”. I believe you have a ComboxBox object in your application, assume:

    ComboBox comboBox1 = ....;
    

    So you can call:

    typeof(ComboBox).GetProperty("SelectedItem")
                    .SetValue(comboBox1, "", null);
    

    If you use .NET 4.5, you can get rid of the last input:

    typeof(ComboBox).GetProperty("SelectedItem")
                    .SetValue(comboBox1, "");
    

    Edit: based on your comment, you don’t need to use reflection, below is you can get combox1 if only knowing the name:

    var comboBox1 = Controls.OfType<ComboBox>()
                          .SingleOrDefault(c => c.Name == "Combobox1");
    
    comboBox1.SelectedItem = "";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code http://jsfiddle.net/xNHKP/6/ (not working in the fiddle for some reason which
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have this code here, which is intended to allow any type of arguments:
I have this code: ie1.link(:text, /Exception:/) It is producing an error message which I
i have this code: lvItem.pszText = (IntPtr)(lpRemoteBuffer + Marshal.SizeOf(typeof(LV_ITEM))); it works fine on 4.0.
I have this code : var listExpression = new List<Expression>(); var parameter = Expression.Parameter(typeof(T));
I have this code // was before var groupTransactions; IEnumerable<IGrouping<TransactionsGroupedByMonthYear, TransactionDto>> groupTransactions = null;
I have this code to keep some configuration data XmlSerializer xmlSerializer = new XmlSerializer(typeof(Entities.Application));
I have this code that works fine: if (typeof jQuery === undefined || jQuery.fn.jquery
I have this code in linux kernel: #define task_cred_xxx(task, xxx) ({ __typeof__(((struct cred *)NULL)->xxx)

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.