Solved

populate comboBox with ColumnHeading from a DataViewGrid and allow editing

Posted on 2008-10-24
3
444 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now