Solved

populate comboBox with ColumnHeading from a DataViewGrid and allow editing

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Desktop Application 3 65
abstract class C# 1 35
Amazon S3 .Net error 5 37
locate sql commands in C# visual studio Project 6 37
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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