By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Combobox.SELECTEDVALUE within a DataGrid

P: n/a
I have a databound combobox within a datagrid. I have set the DisplayMember
and ValueMember.

BUT, how do I capture the Value (SelectedValue) when the user changes the
selection?
Jul 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
pm
Are you using Windows Forms or WebForms the answer will vary.
"Supa Hoopsa" wrote:
I have a databound combobox within a datagrid. I have set the DisplayMember
and ValueMember.

BUT, how do I capture the Value (SelectedValue) when the user changes the
selection?

Jul 21 '05 #2

P: n/a
Sorry, I am using Windows forms.

The combobox contains the names of customers, with the DISPLAYMEMBER set to
CUSTOMERNAME and the VALUEMEMBER set to CUSTOMERKEY.

I haved tried creating a similar combobox outside the datagrid and then
seaching for the text values, but unfortunately the list I have to use has
multiple entries for the same client or clients with the same name, so a text
comparison doesn't work. I need to get at the SELECTEDVALUE of the combobox
so that I can get the customer key.

"pm" wrote:
Are you using Windows Forms or WebForms the answer will vary.
"Supa Hoopsa" wrote:
I have a databound combobox within a datagrid. I have set the DisplayMember
and ValueMember.

BUT, how do I capture the Value (SelectedValue) when the user changes the
selection?

Jul 21 '05 #3

P: n/a
pm
Are you having trouble getting a reference to the combo box in the grid or
having a problem discovering which item was selected having succesfully
obtaining a reference to the specific combo box in the grid?

pm

"Supa Hoopsa" wrote:
Sorry, I am using Windows forms.

The combobox contains the names of customers, with the DISPLAYMEMBER set to
CUSTOMERNAME and the VALUEMEMBER set to CUSTOMERKEY.

I haved tried creating a similar combobox outside the datagrid and then
seaching for the text values, but unfortunately the list I have to use has
multiple entries for the same client or clients with the same name, so a text
comparison doesn't work. I need to get at the SELECTEDVALUE of the combobox
so that I can get the customer key.

"pm" wrote:
Are you using Windows Forms or WebForms the answer will vary.
"Supa Hoopsa" wrote:
I have a databound combobox within a datagrid. I have set the DisplayMember
and ValueMember.

BUT, how do I capture the Value (SelectedValue) when the user changes the
selection?

Jul 21 '05 #4

P: n/a
I reference the combobox in the datagrid by using the code:

datagrid1(datagrid1.currentcell.rownumber,
datagrid1.currentcell.columnnumber)

It's the second part I can't do - discovering which item was selected. I
want to obtain the SELECTEDVALUE of the combobox (ie.e the CUSTOMERKEY in the
example I've shown below).

"pm" wrote:
Are you having trouble getting a reference to the combo box in the grid or
having a problem discovering which item was selected having succesfully
obtaining a reference to the specific combo box in the grid?

pm

"Supa Hoopsa" wrote:
Sorry, I am using Windows forms.

The combobox contains the names of customers, with the DISPLAYMEMBER set to
CUSTOMERNAME and the VALUEMEMBER set to CUSTOMERKEY.

I haved tried creating a similar combobox outside the datagrid and then
seaching for the text values, but unfortunately the list I have to use has
multiple entries for the same client or clients with the same name, so a text
comparison doesn't work. I need to get at the SELECTEDVALUE of the combobox
so that I can get the customer key.

"pm" wrote:
Are you using Windows Forms or WebForms the answer will vary.
"Supa Hoopsa" wrote:

> I have a databound combobox within a datagrid. I have set the DisplayMember
> and ValueMember.
>
> BUT, how do I capture the Value (SelectedValue) when the user changes the
> selection?

Jul 21 '05 #5

P: n/a
pm
private void showSelectedButton_Click(object sender, System.EventArgs e) {
int selectedIndex = comboBox1.SelectedIndex;
Object selectedItem = comboBox1.SelectedItem;

MessageBox.Show("Selected Item Text: " + selectedItem.ToString()
+ "\n" +
"Index: " + selectedIndex.ToString());
}
"Supa Hoopsa" wrote:
I reference the combobox in the datagrid by using the code:

datagrid1(datagrid1.currentcell.rownumber,
datagrid1.currentcell.columnnumber)

It's the second part I can't do - discovering which item was selected. I
want to obtain the SELECTEDVALUE of the combobox (ie.e the CUSTOMERKEY in the
example I've shown below).

"pm" wrote:
Are you having trouble getting a reference to the combo box in the grid or
having a problem discovering which item was selected having succesfully
obtaining a reference to the specific combo box in the grid?

pm

"Supa Hoopsa" wrote:
Sorry, I am using Windows forms.

The combobox contains the names of customers, with the DISPLAYMEMBER set to
CUSTOMERNAME and the VALUEMEMBER set to CUSTOMERKEY.

I haved tried creating a similar combobox outside the datagrid and then
seaching for the text values, but unfortunately the list I have to use has
multiple entries for the same client or clients with the same name, so a text
comparison doesn't work. I need to get at the SELECTEDVALUE of the combobox
so that I can get the customer key.

"pm" wrote:

> Are you using Windows Forms or WebForms the answer will vary.
>
>
> "Supa Hoopsa" wrote:
>
> > I have a databound combobox within a datagrid. I have set the DisplayMember
> > and ValueMember.
> >
> > BUT, how do I capture the Value (SelectedValue) when the user changes the
> > selection?

Jul 21 '05 #6

P: n/a
pm
private void showSelectedButton_Click(object sender, System.EventArgs e) {
int selectedIndex = comboBox1.SelectedIndex;
Object selectedItem = comboBox1.SelectedItem;

MessageBox.Show("Selected Item Text: " + selectedItem.ToString()
+ "\n" +
"Index: " + selectedIndex.ToString());
}
"Supa Hoopsa" wrote:
I reference the combobox in the datagrid by using the code:

datagrid1(datagrid1.currentcell.rownumber,
datagrid1.currentcell.columnnumber)

It's the second part I can't do - discovering which item was selected. I
want to obtain the SELECTEDVALUE of the combobox (ie.e the CUSTOMERKEY in the
example I've shown below).

"pm" wrote:
Are you having trouble getting a reference to the combo box in the grid or
having a problem discovering which item was selected having succesfully
obtaining a reference to the specific combo box in the grid?

pm

"Supa Hoopsa" wrote:
Sorry, I am using Windows forms.

The combobox contains the names of customers, with the DISPLAYMEMBER set to
CUSTOMERNAME and the VALUEMEMBER set to CUSTOMERKEY.

I haved tried creating a similar combobox outside the datagrid and then
seaching for the text values, but unfortunately the list I have to use has
multiple entries for the same client or clients with the same name, so a text
comparison doesn't work. I need to get at the SELECTEDVALUE of the combobox
so that I can get the customer key.

"pm" wrote:

> Are you using Windows Forms or WebForms the answer will vary.
>
>
> "Supa Hoopsa" wrote:
>
> > I have a databound combobox within a datagrid. I have set the DisplayMember
> > and ValueMember.
> >
> > BUT, how do I capture the Value (SelectedValue) when the user changes the
> > selection?

Jul 21 '05 #7

P: n/a
Sorry, I'm still pretty green with .NET.

Two questions:

1. What does this code look like in VB.NET. I tried typing this in (removing
the {}), but I get an error on the Private Void line saying "End of Statement
expected"

2. More importantly, how does this work? I've never encountered "void"

Sorry to be a pain, your help is REALLY appreciated.

"pm" wrote:
private void showSelectedButton_Click(object sender, System.EventArgs e) {
int selectedIndex = comboBox1.SelectedIndex;
Object selectedItem = comboBox1.SelectedItem;

MessageBox.Show("Selected Item Text: " + selectedItem.ToString()
+ "\n" +
"Index: " + selectedIndex.ToString());
}
"Supa Hoopsa" wrote:
I reference the combobox in the datagrid by using the code:

datagrid1(datagrid1.currentcell.rownumber,
datagrid1.currentcell.columnnumber)

It's the second part I can't do - discovering which item was selected. I
want to obtain the SELECTEDVALUE of the combobox (ie.e the CUSTOMERKEY in the
example I've shown below).

"pm" wrote:
Are you having trouble getting a reference to the combo box in the grid or
having a problem discovering which item was selected having succesfully
obtaining a reference to the specific combo box in the grid?

pm

"Supa Hoopsa" wrote:

> Sorry, I am using Windows forms.
>
> The combobox contains the names of customers, with the DISPLAYMEMBER set to
> CUSTOMERNAME and the VALUEMEMBER set to CUSTOMERKEY.
>
> I haved tried creating a similar combobox outside the datagrid and then
> seaching for the text values, but unfortunately the list I have to use has
> multiple entries for the same client or clients with the same name, so a text
> comparison doesn't work. I need to get at the SELECTEDVALUE of the combobox
> so that I can get the customer key.
>
> "pm" wrote:
>
> > Are you using Windows Forms or WebForms the answer will vary.
> >
> >
> > "Supa Hoopsa" wrote:
> >
> > > I have a databound combobox within a datagrid. I have set the DisplayMember
> > > and ValueMember.
> > >
> > > BUT, how do I capture the Value (SelectedValue) when the user changes the
> > > selection?

Jul 21 '05 #8

P: n/a
pm
Private Sub showSelectedButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim selectedIndex As Integer
selectedIndex = comboBox1.SelectedIndex
Dim selectedItem As Object
selectedItem = comboBox1.SelectedItem

MessageBox.Show("Selected Item Text: " & selectedItem.ToString() &
Microsoft.VisualBasic.Constants.vbCrLf & _
"Index: " & selectedIndex.ToString())
"Supa Hoopsa" wrote:
Sorry, I'm still pretty green with .NET.

Two questions:

1. What does this code look like in VB.NET. I tried typing this in (removing
the {}), but I get an error on the Private Void line saying "End of Statement
expected"

2. More importantly, how does this work? I've never encountered "void"

Sorry to be a pain, your help is REALLY appreciated.

"pm" wrote:
private void showSelectedButton_Click(object sender, System.EventArgs e) {
int selectedIndex = comboBox1.SelectedIndex;
Object selectedItem = comboBox1.SelectedItem;

MessageBox.Show("Selected Item Text: " + selectedItem.ToString()
+ "\n" +
"Index: " + selectedIndex.ToString());
}
"Supa Hoopsa" wrote:
I reference the combobox in the datagrid by using the code:

datagrid1(datagrid1.currentcell.rownumber,
datagrid1.currentcell.columnnumber)

It's the second part I can't do - discovering which item was selected. I
want to obtain the SELECTEDVALUE of the combobox (ie.e the CUSTOMERKEY in the
example I've shown below).

"pm" wrote:

> Are you having trouble getting a reference to the combo box in the grid or
> having a problem discovering which item was selected having succesfully
> obtaining a reference to the specific combo box in the grid?
>
> pm
>
> "Supa Hoopsa" wrote:
>
> > Sorry, I am using Windows forms.
> >
> > The combobox contains the names of customers, with the DISPLAYMEMBER set to
> > CUSTOMERNAME and the VALUEMEMBER set to CUSTOMERKEY.
> >
> > I haved tried creating a similar combobox outside the datagrid and then
> > seaching for the text values, but unfortunately the list I have to use has
> > multiple entries for the same client or clients with the same name, so a text
> > comparison doesn't work. I need to get at the SELECTEDVALUE of the combobox
> > so that I can get the customer key.
> >
> > "pm" wrote:
> >
> > > Are you using Windows Forms or WebForms the answer will vary.
> > >
> > >
> > > "Supa Hoopsa" wrote:
> > >
> > > > I have a databound combobox within a datagrid. I have set the DisplayMember
> > > > and ValueMember.
> > > >
> > > > BUT, how do I capture the Value (SelectedValue) when the user changes the
> > > > selection?

Jul 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.