469,936 Members | 2,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

Combobox.SELECTEDVALUE within a DataGrid

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
8 2587
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
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
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
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
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
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
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
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.

Similar topics

3 posts views Thread by Bill C. | last post: by
2 posts views Thread by pei_world | last post: by
6 posts views Thread by Mike Caputo | last post: by
2 posts views Thread by pmcguire | last post: by
30 posts views Thread by dbuchanan | last post: by
8 posts views Thread by Supa Hoopsa | last post: by
1 post views Thread by fiaolle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.