Note that there are some explanatory texts on larger screens.

plurals
  1. POReorder columns in datatable?
    text
    copied!<p>I'm using xsd files to validate xml files. In the xsd files, only a few of the elements are required and the rest are optional. However, it is sequential so the order of the elements as they appear in the datatable matter lots. After considering a few scenarios the user may encounter, I came up with a case that I have a little trouble solving.</p> <p>The case is this: For example, There are 6 elements A, B, C, D, E, F in the xsd file. Only A, C, and D are needed. The user starts off with A, C, D. I allow the user to add a column, with the name B. However, it gets attached on the end: A, C, D, B. Therefore, since it's sequential, it will not validate.</p> <p>So my question is, how do I insert B between A and C in order for the xsd validation to pass? Or is there any other way to reorder the things in the datagridview and reflect that in the datatable?</p> <p>I thought I would be able to solve the problem by allowing the user to reorder the columns in the datagridview where the table is displayed.</p> <p>EDIT: Under the assumption that I cannot alter the xsd files.</p> <p>That is,</p> <pre><code> dataGridView1.AllowUserToOrderColumns = true; </code></pre> <p>However, the validation always told me that an "element" after the last necessary element was expected. This means that the shift in the datacolumn in the datagridview was not reflected in the datatable itself.</p> <p>In order to pass the validation, I believe I would need to insert the column in the respective place it is relative to everything else. Or at least insert it at the end and reflect the proper order when the user presses the validate button.</p> <p>I've come across some other things online telling me to try things like:</p> <pre><code> Table.Columns["Column Name"].SetOrdinal(NewIndex); </code></pre> <p>But I have not yet implemented it. Any ideas in case that line above doesn't work? =) Additionally, I want to be able to sync the datatable with what the user does in the datagridview. That would be ideal. If the user moves the columns in the datagridview, the datatable should reflect that change. </p> <p>Any insight is greatly appreciated, I'll be happy to offer additional information if needed. Thanks!</p> <p>Sincerely, tf.rz </p> <p>(.NET 3.5 SP1, Visual Studio C# 2008)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload