Click here to Skip to main content
14,735,305 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to set image in GridViewImageColumn. All is OK, but when I'm adding new row, I'm receiving error: column "IsMetadata" does not belong to table.

What I have tried:

I'm adding new row by buttom:

private void bt_AddNew_Click(object sender, EventArgs e)
     GridViewName.ReadOnly = false;
     GridViewName.AllowAddNewRow = false;

then I want to display in column "column1" image:

private void GridViewName_CellFormatting(object sender, CellFormattingEventArgs e)
      if (e.Column.Name == "column1")
          if (e.CellElement.RowInfo.Cells["IsMetadata"].Value != DBNull.Value)
              if (Convert.ToBoolean(e.CellElement.RowInfo.Cells["IsMetadata"].Value))
                  e.CellElement.Image = Accountant.Properties.Resources.WasashleliPapka;
                  e.CellElement.ImageAlignment = ContentAlignment.MiddleLeft;
                  e.CellElement.TextImageRelation = TextImageRelation.ImageBeforeText;

Please help, how to avoid this error: "column does not belong to table"
Updated 18-Jan-18 3:27am

1 solution

We can;t help you with that: we have no access to your GridView while it is running, or you your data source at all - and that is what you need.

The error is clear: there is no column in the data source from which your table was populated that is called "IsMetadata".
Why not? We don't know!

So, its going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
Member 12361495 18-Jan-18 8:34am
I debug all line, Column "IsMetadata" is in gridview, if I use another column, for example "column555", I will get same error, even if the column exists. in CellFormatting void I cannot get dgview.SelectedRows[0].Cells["IsMetadata"].Value.ToString(), column exists, but I get error.
Member 12361495 18-Jan-18 8:39am
May be when I'm adding a row in gridview incorrect???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900