Solved

populate comboBox with ColumnHeading from a DataViewGrid and allow editing

Posted on 2008-10-24
3
442 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

9 Experts available now in Live!

Get 1:1 Help Now