471,863 Members | 978 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

datagridview from xml


Problem - An extra column to the left (even with row headers disabled)

Apologies if this posting is already in the newsgroup; but have changed to
40tude and can't see it in the newly dowloaded messages. It was originally
html (tut tut) so maybe it didn't register. I have tried a new xml file and
generated a new xsd file from it using xsd.exe and now the xml file
produces three columns. The first contains no data and the other two
contain the data in the xml file. So I am now getting 3 columns for 2 data
elements. Does the etiquette of this news group allow attachment of the xml
and xsd files?

Original posting

I'm writing a winform app (as practice) that has as one of its features a
button that reads an xml file to a datagridview.

No matter what I do I get two columns instead of one.
(Now three instaed of two)

The "first column", I retrieve and place the text "Holy Cat" in its header
text. This column contains no data from the xml file.

The second (and now third) columns contain the correct data from the xml

When clicked the "first column" is not shown as a column by the event
delegate; but the "second column" reports that it is column 1. and the
third column is reported as column 3.

Can anybody spot the bug in my code?



-------------- snip --------------------------
private void btnIgnoreListClick(object sender, System.EventArgs e)


int formDown = 300;

int formAcross = 400;

/* create a new form to hold a datagridview */

System.Windows.Forms.Form dataGridForm = new Form();

/* suspend display till later */


/* Set the caption text of the form. */

dataGridForm.Text = "Exclude List";

/* Display a help button on the form. */

dataGridForm.HelpButton = true;

/* Define the border style of the form to a dialog box. */

dataGridForm.FormBorderStyle = FormBorderStyle.FixedDialog;

/* Set the MaximizeBox to false to remove the maximize box. */

dataGridForm.MaximizeBox = false;

/* Set the MinimizeBox to false to remove the minimize box. */

dataGridForm.MinimizeBox = false;

/* Set the accept button of the form to button1. */

/* Set the start position of the form to the center of the screen. */

dataGridForm.StartPosition = FormStartPosition.CenterScreen;

/* parameterize the browse */

dataGridForm.Size = new System.Drawing.Size(formAcross,formDown);

/* Create two buttons to use as the accept and cancel buttons. */

System.Windows.Forms.Button button1 = new Button ();

System.Windows.Forms.Button button2 = new Button ();

/* Set the text of button1 to "OK" and "Cancel" */

button1.Text = "OK";

button2.Text = "Cancel";

/* Add button1 to the form. */


/* Set the position of the button1 */

button1.Location = new Point (formAcross-200,formDown-60);

/* Add button2 to the form. */


/* Set the position of the button2 */

button2.Location = new Point (formAcross-300,formDown-60);

/* set the buttons to particular events */

/* Set the accept button of the form to button1. */

dataGridForm.AcceptButton = button1;

/* Set the cancel button of the form to button2. */

dataGridForm.CancelButton = button2;

/* create and position the datagridview */

System.Windows.Forms.DataGridView ignoreDataGridView = new DataGridView();


/* don't want row headers */

ignoreDataGridView.RowHeadersVisible = false;

ignoreDataGridView.Location = new System.Drawing.Point(10,10);

ignoreDataGridView.Size = new System.Drawing.Size(formAcross-20,

ignoreDataGridView.TabIndex = 10;

ignoreDataGridView.ColumnCount = 1;

/* style */

DataGridViewCellStyle style = new DataGridViewCellStyle();

style.BackColor = Color.Bisque;

style.SelectionBackColor = Color.LightBlue;

style.ForeColor = Color.Navy;

style.Font = new Font("Arial",8,FontStyle.Bold);

style.Padding = new Padding(5,2,5,5);

ignoreDataGridView.DefaultCellStyle = style;

/* data source connection */

ignoreDataGridView.AutoGenerateColumns = true;

/* completely fill the parent controls' canvas */

ignoreDataGridView.Dock = DockStyle.Top;

/* Create a data set to hold IgnoreList */

DataSet ds = new DataSet();

/* Read in the schema that describes the ignoreList.xml file */


/* Read in the data from the xml file */

ds.ReadXml(@"c:\csharp\ignoreList.xml",XmlReadMode .ReadSchema);


// debugging

foreach (DataTable table in ds.Tables)





/* associate xml table with datgridview */

/* either or */

// ignoreDataGridView.DataSource = ds.Tables[0].DefaultView;

ignoreDataGridView.DataSource = ds;

ignoreDataGridView.DataMember = "ignoreDirectory";

ignoreDataGridView.SelectionMode =

ignoreDataGridView.CellContentClick +=

new DataGridViewCellEventHandler(this.ignoreDataGridVi ew_CellContentClick);

/* set the header text of the first column */

DataGridViewColumn column1 = ignoreDataGridView.Columns[0];

column1.HeaderText = "Holy Cat";

/* add the brows to the form */


/* Display the browse in the form. */







private void ignoreDataGridView_CellContentClick(object sender,
DataGridViewCellEventArgs e)


MessageBox.Show("Number of Column"+ e.ColumnIndex.ToString());


--------------- end snip --------------
Feb 2 '06 #1
1 4534

The (temporary) workaround is to set the extra column to Visible = false;

DataGridViewColumn column1 = ignoreDataGridView.Columns[0];

column1.Visible = false;

Feb 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by DraguVaso | last post: by
10 posts views Thread by Henok Girma | last post: by
7 posts views Thread by Mitchell S. Honnert | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
reply views Thread by jeastman - Hotmail | last post: by
3 posts views Thread by Andrus | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.