473,418 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

datagridview from xml

Hi,

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
file.

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?

TIA

Regards
Mark

-------------- 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 */

dataGridForm.SuspendLayout();

/* 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. */

dataGridForm.Controls.Add(button1);

/* Set the position of the button1 */

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

/* Add button2 to the form. */

dataGridForm.Controls.Add(button2);

/* 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();

ignoreDataGridView.SuspendLayout();

/* don't want row headers */

ignoreDataGridView.RowHeadersVisible = false;

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

ignoreDataGridView.Size = new System.Drawing.Size(formAcross-20,
formDown-100);

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 */

ds.ReadXmlSchema(@"c:\csharp\ignoreList.xsd");

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

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

/*

// debugging

foreach (DataTable table in ds.Tables)

{

MessageBox.Show(table.TableName.ToString());

}

*/

/* associate xml table with datgridview */

/* either or */

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

ignoreDataGridView.DataSource = ds;

ignoreDataGridView.DataMember = "ignoreDirectory";

ignoreDataGridView.SelectionMode =
DataGridViewSelectionMode.RowHeaderSelect;

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 */

dataGridForm.Controls.Add(ignoreDataGridView);

/* Display the browse in the form. */

dataGridForm.ResumeLayout();

ignoreDataGridView.ResumeLayout();

dataGridForm.ShowDialog();

ignoreDataGridView.Show();

dataGridForm.Dispose();

}

private void ignoreDataGridView_CellContentClick(object sender,
DataGridViewCellEventArgs e)

{

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

}

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.