473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

changing a datagrid to a combo box

Hi

I have the following code (not mine) that populates a datagrid with some
file names. But I want to replace the datagrid with a combo box.
private void OnCurrentDataCellChanged(object sender, System.EventArgs e)

{try{

DataSet ds = dgMembers.DataSource as DataSet;

txtData.Text =
ds.Tables[0].Rows[dgMembers.CurrentCell.RowNumber].ItemArray.GetValue(0).ToString();

dataset = txtData.Text;

}catch}}

How can i work out what to change to make a combo box, say cmbMembers, have
the values that the datagrid used to have?

Thanks

Doug
Nov 17 '05 #1
3 2974
Hi,

not quite sure I got u right.

FYI: ComboBox can only display 1 column, DataGrid can display all columns

If you can live with just displaying 1 column you just have to set ComboBox.DataSoure and ComboBox.DisplayMember (column).

If you want to display more than 1 column and are willing to programm a few lines you just leave ComboBox.DataSoure and ComboBox.DisplayMember empty and fill the ComboBox yourself.
// helper class defined in your form to use only with your form
public class ComboBoxDisplayEnhancementRecord {
public DataRow mRow;
public ComboBoxDisplayEnhancementRecord(DataRow iRow) {
mRow = iRow;
}
// the ComboBox Items property uses ToString() to display text no matter WHAT type of
// object contained, so we adapt the ToString() to match our purpose.
public override string ToString() {
return mRow[0].ToString()+" "+mRow[1].ToString();
}
}
// how to fill the combobox
private void button1_Click(object sender, System.EventArgs e) {
// magic here is to just wrap the DataRow with our little enhancer class...
foreach(DataRow Row in dataSet11.Tables[0].Rows)
comboBox1.Items.Add(new ComboBoxDisplayEnhancementRecord(Row));
}
// how to find out which ROW was selected
private void button2_Click(object sender, System.EventArgs e) {
if ((comboBox1.SelectedItem != null) &&
(comboBox1.SelectedItem.GetType() == typeof(ComboBoxDisplayEnhancementRecord)))
MessageBox.Show(
((ComboBoxDisplayEnhancementRecord)comboBox1.Selec tedItem).mRow[2].ToString());
}
Inner classes are cooool!

"Doug" <qu********@hotmail.com> schrieb im Newsbeitrag news:43***********************@news.optusnet.com.a u...
Hi

I have the following code (not mine) that populates a datagrid with some
file names. But I want to replace the datagrid with a combo box.
private void OnCurrentDataCellChanged(object sender, System.EventArgs e)

{try{

DataSet ds = dgMembers.DataSource as DataSet;

txtData.Text =
ds.Tables[0].Rows[dgMembers.CurrentCell.RowNumber].ItemArray.GetValue(0).ToString();

dataset = txtData.Text;

}catch}}

How can i work out what to change to make a combo box, say cmbMembers, have
the values that the datagrid used to have?

Thanks



Doug

Nov 17 '05 #2
Thanks Robert,

I am a beginner and I am just hoping for a tip about a really simple way to change the properties of a single column datagrid to be able to be replaced by a combo box.

Like what things in the code below need to be changed if I want to delete the datagrid and substitute a combo box (ie in my example from dgMembers to cmbMembers).

Also in another part of the form, i have an OldeDbDataAdapter routine that has
OleDbDataAdapter da = new OleDbDataAdapter();

DataSet ds = new DataSet();

da.Fill(ds, adorecordset, "data");

dgMembers.SetDataBinding(ds, "data");

I dont think that i can simply substitute the dgMembers.SetDataBinding(ds, "data") with cmbMembers.SetDataBinding(ds, "data") because SetDataBindings may not be a property of a combobox?

I'm not at the level where i understand you code (even though I am sure your code is very accurate).

is it possible to change "txtData.Text = ds.Tables[0].Rows[dgMembers.CurrentCell.RowNumber].ItemArray.GetValue(0).ToString(); to

something like txtData.Text = cmbMembers.SelectedIndex.ToString; ??

and how would i emulate the SetDataBindings for a combo box?


"Robert Heuvel" <ro***********@isopass.com> wrote in message news:Ot**************@tk2msftngp13.phx.gbl...
Hi,

not quite sure I got u right.

FYI: ComboBox can only display 1 column, DataGrid can display all columns

If you can live with just displaying 1 column you just have to set ComboBox.DataSoure and ComboBox.DisplayMember (column).

If you want to display more than 1 column and are willing to programm a few lines you just leave ComboBox.DataSoure and ComboBox.DisplayMember empty and fill the ComboBox yourself.
// helper class defined in your form to use only with your form
public class ComboBoxDisplayEnhancementRecord {
public DataRow mRow;
public ComboBoxDisplayEnhancementRecord(DataRow iRow) {
mRow = iRow;
}
// the ComboBox Items property uses ToString() to display text no matter WHAT type of
// object contained, so we adapt the ToString() to match our purpose.
public override string ToString() {
return mRow[0].ToString()+" "+mRow[1].ToString();
}
}
// how to fill the combobox
private void button1_Click(object sender, System.EventArgs e) {
// magic here is to just wrap the DataRow with our little enhancer class...
foreach(DataRow Row in dataSet11.Tables[0].Rows)
comboBox1.Items.Add(new ComboBoxDisplayEnhancementRecord(Row));
}
// how to find out which ROW was selected
private void button2_Click(object sender, System.EventArgs e) {
if ((comboBox1.SelectedItem != null) &&
(comboBox1.SelectedItem.GetType() == typeof(ComboBoxDisplayEnhancementRecord)))
MessageBox.Show(
((ComboBoxDisplayEnhancementRecord)comboBox1.Selec tedItem).mRow[2].ToString());
}
Inner classes are cooool!

"Doug" <qu********@hotmail.com> schrieb im Newsbeitrag news:43***********************@news.optusnet.com.a u...
Hi

I have the following code (not mine) that populates a datagrid with some
file names. But I want to replace the datagrid with a combo box.
private void OnCurrentDataCellChanged(object sender, System.EventArgs e)

{try{

DataSet ds = dgMembers.DataSource as DataSet;

txtData.Text =
ds.Tables[0].Rows[dgMembers.CurrentCell.RowNumber].ItemArray.GetValue(0).ToString();

dataset = txtData.Text;

}catch}}

How can i work out what to change to make a combo box, say cmbMembers, have
the values that the datagrid used to have?

Thanks



Doug

Nov 17 '05 #3
You r in a tight spot!

If u really only have a 1 column datagrid problem it is very easy to substitute.

these changes you make with the form designer (SHIFT+F7) and the property editor!

- remove the DataGrid
- place the ComboBox on the form
- have ComboBox.DataSource point to your dataset
- have ComboBox.DisplayMember point to your 1 column

after your "da.Fill" the dataset the ComboBox should display the data.

you don't have to manually "fiddle" around with SetDataBinding & co.

so as to your code:

OleDbDataAdapter da = new OleDbDataAdapter(); // ok
DataSet ds = new DataSet(); // ok
da.Fill(ds, adorecordset, "data"); // ok
dgMembers.SetDataBinding(ds, "data"); // omit

Caution, don't fiddle around in the method InitializeComponent()!
"Doug" <qu********@hotmail.com> schrieb im Newsbeitrag news:43***********************@news.optusnet.com.a u...
Thanks Robert,

I am a beginner and I am just hoping for a tip about a really simple way to change the properties of a single column datagrid to be able to be replaced by a combo box.

Like what things in the code below need to be changed if I want to delete the datagrid and substitute a combo box (ie in my example from dgMembers to cmbMembers).

Also in another part of the form, i have an OldeDbDataAdapter routine that has
OleDbDataAdapter da = new OleDbDataAdapter();

DataSet ds = new DataSet();

da.Fill(ds, adorecordset, "data");

dgMembers.SetDataBinding(ds, "data");

I dont think that i can simply substitute the dgMembers.SetDataBinding(ds, "data") with cmbMembers.SetDataBinding(ds, "data") because SetDataBindings may not be a property of a combobox?

I'm not at the level where i understand you code (even though I am sure your code is very accurate).

is it possible to change "txtData.Text = ds.Tables[0].Rows[dgMembers.CurrentCell.RowNumber].ItemArray.GetValue(0).ToString(); to

something like txtData.Text = cmbMembers.SelectedIndex.ToString; ??

and how would i emulate the SetDataBindings for a combo box?


"Robert Heuvel" <ro***********@isopass.com> wrote in message news:Ot**************@tk2msftngp13.phx.gbl...
Hi,

not quite sure I got u right.

FYI: ComboBox can only display 1 column, DataGrid can display all columns

If you can live with just displaying 1 column you just have to set ComboBox.DataSoure and ComboBox.DisplayMember (column).

If you want to display more than 1 column and are willing to programm a few lines you just leave ComboBox.DataSoure and ComboBox.DisplayMember empty and fill the ComboBox yourself.
// helper class defined in your form to use only with your form
public class ComboBoxDisplayEnhancementRecord {
public DataRow mRow;
public ComboBoxDisplayEnhancementRecord(DataRow iRow) {
mRow = iRow;
}
// the ComboBox Items property uses ToString() to display text no matter WHAT type of
// object contained, so we adapt the ToString() to match our purpose.
public override string ToString() {
return mRow[0].ToString()+" "+mRow[1].ToString();
}
}
// how to fill the combobox
private void button1_Click(object sender, System.EventArgs e) {
// magic here is to just wrap the DataRow with our little enhancer class...
foreach(DataRow Row in dataSet11.Tables[0].Rows)
comboBox1.Items.Add(new ComboBoxDisplayEnhancementRecord(Row));
}
// how to find out which ROW was selected
private void button2_Click(object sender, System.EventArgs e) {
if ((comboBox1.SelectedItem != null) &&
(comboBox1.SelectedItem.GetType() == typeof(ComboBoxDisplayEnhancementRecord)))
MessageBox.Show(
((ComboBoxDisplayEnhancementRecord)comboBox1.Selec tedItem).mRow[2].ToString());
}
Inner classes are cooool!

"Doug" <qu********@hotmail.com> schrieb im Newsbeitrag news:43***********************@news.optusnet.com.a u...
Hi

I have the following code (not mine) that populates a datagrid with some
file names. But I want to replace the datagrid with a combo box.
private void OnCurrentDataCellChanged(object sender, System.EventArgs e)

{try{

DataSet ds = dgMembers.DataSource as DataSet;

txtData.Text =
ds.Tables[0].Rows[dgMembers.CurrentCell.RowNumber].ItemArray.GetValue(0).ToString();

dataset = txtData.Text;

}catch}}

How can i work out what to change to make a combo box, say cmbMembers, have
the values that the datagrid used to have?

Thanks



Doug

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
0
by: JL3574 l | last post by:
i have a datagrid with a combo box added in it's columns . the combobox pulls values from a database in it's dropdownlist fashion. my problem is that when i pick a select on the combo box it...
4
by: Ziv Riezman | last post by:
Hi All I Have a datagrid on asp.net. i need to add a combo box column that chages it's data according to a spefiiec row in a datagrid. Please help me ?? Thnaks Ziv Riezman
2
by: pmcguire | last post by:
OK. So I've been to http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp and learned a lot about what I might do with a datagrid. But I'm STILL not able to do what I want to do. I want to be able...
2
by: pmcguire | last post by:
I have derived a ComboBoxColumnStyle that inherits DataGridColumnStyle. It works fine except for one behavior. If the user selects a new value from the ComboBox's pulldown list on a brand new...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
2
by: kenglish_hi | last post by:
hello, I have a form with a datagrid and combo box. When the form loads up, i want the focus to be on the combo box. however, whenever it loads up, the focus is always on the datagrid. in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.