Solved

populate comboBox with ColumnHeading from a DataViewGrid and allow editing

Posted on 2008-10-24
3
447 Views
Last Modified: 2008-10-24
Hi i was wondering if anyone could point me in the direction of, or explain to me some .NET C# code that will populate a comboBox with the ColumnHeading value of my DataGridView.

And to extend on that, code that will allow me to edit the comboBox having the changes renaming that particular column head

Im using Visual Studios C# .Net 3.0 i think
0
Comment
Question by:A_Kardas
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 200 total points
ID: 22800050
To populate combobox You can do like this

            comboBox1.Items.Clear();
            foreach( DataGridViewColumn dgvc in dataGridView1.Columns)
                comboBox1.Items.Add(dgvc.HeaderText);
As to edit, You should explain, how it should work.
0
 

Author Comment

by:A_Kardas
ID: 22800720
ok that works perfectly as i wanted, now so i select Column1 for instance from the combobox. And i change that value to ID_Num, and click a button i have.

then the value in the coresponding column header becomes ID_Num

is it just going to be something as simple as

DataGridViewColumn = comboBox1.text     ? an i on the right track? i assume there is going to have to be an index or something so it knows which header to change.

sorry quite new to c# and programming in general, but looks like i have found a great place to read up and learn
0
 
LVL 17

Expert Comment

by:mokule
ID: 22800783
I wouldn't do this by editing comboBox.
It wouldn't be user friendly
I would rather do this by adding textbox for inputing new header text.
Moreover the code would be much simpler then

            dataGridView1.Columns[comboBox1.SelectedIndex].HeaderText = textBox1.Text;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question