• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Getting the default value of a databound combobox

I have a combobox that is populated like this

                Me.cbReportParam.DisplayMember = "Name"
                Me.cbReportParam.ValueMember = "Name_ID"
                Me.cbReportParam.DataSource = ds.Tables("Names")

It populates correctly. So the first selection is "Adam". How do I get the name to my variable strName?
When I try strName = me.cbReportParam.SelectedItem it returns {System.Data.DataRowView}
I dont want to hardcode "Adam" because a name could be added before it later on.
0
bertino12
Asked:
bertino12
  • 3
  • 3
1 Solution
 
Stephen MandersonSoftware EngineerCommented:
Hi there,

use the .SelectedText property for this

Regards
Steve
0
 
bertino12Author Commented:
It returns ""
0
 
Stephen MandersonSoftware EngineerCommented:
Try

Me.StrName = Me.cbReportParam.SelectedItem.ToString

Regards
Steve
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
bertino12Author Commented:
That gave me "System.Data.DataRowView"


strName = CType(cbReportParam.SelectedItem, DataRowView).Item("Name")
finally got it working
0
 
Stephen MandersonSoftware EngineerCommented:
Good to hear it,

Weird I couldnt recreate the problem..

I could get it to show the string with either selectedtext or selecteditem with it being databound

Anyways all the best!
Steve


0
 
bertino12Author Commented:
Thanks for the time :P
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now