5 Replies - 735 Views - Last Post: 25 January 2019 - 09:45 AM

#1 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

How to Add a Column?

Posted 22 January 2019 - 09:15 AM

I'm trying to add a column in CLI C++ and having some difficulty with the syntax. I thought it would be similar to C#; but of course, with this awful language it's never as easy as it should be.

dataGridView1->Columns->Add(line);



"no instance of overloaded function Add matches the argument list"

in C# I do it like this:

dt.Columns.Add(t, typeof(string));



but this would also work.. so the C# method will accept either one or two arguments as far as I can tell

dt.Columns.Add(t);



of course, that's a DataTable not a dataGridView so... perhaps the method takes a different set of overloads? I looked online and it appears the syntax above should work. Does anyone have any idea what I did wrong? Again, the C++ resources are harder to find. It looks like this is using the same library so I'm just confused why it wouldn't accept the same argument list.


I saw a few posts saying that I could create a binding context for this similar to WPF. I would also settle for an answer on how that would be done, although I'm really just looking to do this the winforms way. I know Iknow, winforms is not the right way but again I'm just adding tiny features to a legacy app and curious how this would be done.

thank you! :tooth:/>/>

This post has been edited by hexagod: 22 January 2019 - 09:16 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to Add a Column?

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,942
  • Joined: 12-December 12

Re: How to Add a Column?

Posted 22 January 2019 - 09:23 AM

I assume this link might be relevant, although it looks a bit old.

Looks to be something like DataGridViewColumn ^ colFirstName = gcnew DataGridViewColumn;, or more extensively

DataGridViewColumn ^ colFullName = gcnew DataGridViewColumn;
        DataGridViewCell ^ celFullName = gcnew DataGridViewTextBoxCell;
        colFullName->CellTemplate = celFullName;
        dgvStudents->Columns->Add(colFullName);


although I couldn't tell you about C++. [I didn't know anybody ever worked with WinForms via C++ :sweatdrop:, sounds like a bit of an oxymoron. ]
Was This Post Helpful? 0
  • +
  • -

#3 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: How to Add a Column?

Posted 22 January 2019 - 09:54 AM

It looks like in C++ this method requires two string arguments because this will compile... however, I don't know what the second argument does:

dataGridView1->Columns->Add("", "");



EDIT: according to intellisense it's name and column header. Interesting that C# only needs one argument while VC++ req two

This post has been edited by hexagod: 22 January 2019 - 10:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: How to Add a Column?

Posted 22 January 2019 - 10:44 AM

View Postandrewsw, on 22 January 2019 - 09:23 AM, said:

although I couldn't tell you about C++. [I didn't know anybody ever worked with WinForms via C++ :sweatdrop:/>, sounds like a bit of an oxymoron. ]


yeah that's because C++ + winforms is ridiculous and there's no reason any sane person would choose to develop apps with it nowadays. only reason that I did was that I was a beginner programmer and like "oh I've heard of Visual C++ I'll use that language" and I already knew how the forms worked because I used to make websites with webforms in html. I wasn't expecting this program to be as useful as it turned out to be, years later, which is why I still use the language.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6821
  • View blog
  • Posts: 23,201
  • Joined: 05-May 12

Re: How to Add a Column?

Posted 24 January 2019 - 08:49 PM

View Posthexagod, on 22 January 2019 - 11:54 AM, said:

dataGridView1->Columns->Add("", "");



EDIT: according to intellisense it's name and column header. Interesting that C# only needs one argument while VC++ req two

C# requires two parameters as well. The one parameter version require a DataGridViewColumn to be passed in. The two parameter version requires two strings.

I think you are confusing yourself between the DataGridView and the DataTable. They are two completely different animals.
Was This Post Helpful? 0
  • +
  • -

#6 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: How to Add a Column?

Posted 25 January 2019 - 09:45 AM

Yeah I know they're different but I didn't realize that the methods had different argument specs.

DataTable->Add() will accept one or two afaik
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1