Click here to Skip to main content
15,886,049 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have four rows in a DataGridView and the structure of the datagridview is already defined as
HOSTNAME IP_ADDRESS USERNAME PASSWORD

I am loading the data from a xml file and the file looks like this
XML
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table1>
    <Host-Name>ixin-sovit</Host-Name>
    <Ip_Address>10.205.29.19</Ip_Address>
    <User_Name>sovit</User_Name>
    <Password>12345</Password>
  </Table1>
</NewDataSet>


When i am loading the form at load time, the datagridview looks like this

HOSTNAME IP_ADDRESS USERNAME PASSWORD
12345

Rest of the columns are not getting populated
The code i am using is
C#
if (File.Exists(@"D:\HostAdded.xml") && new FileInfo(@"D:\HostAdded.xml").Length != 0)
{
                    dataGridView1.DefaultCellStyle.ForeColor = Color.Red;
                    DataSet dataSet = new DataSet(); 
                    dataSet.ReadXml(@"D:\HostAdded.xml");
                    dataGridView1.AutoGenerateColumns = false;
                    dataGridView1.DataSource = dataSet;
                    dataGridView1.DataMember = "Table1";
                    this.Cursor = Cursors.Default;
}


I am unable to understand where the problem is??

Looking forward to your response!!!
Thanks :)
Posted
Comments
sovit agarwal 20-May-14 2:40am    
May i know how to do that?
DamithSL 20-May-14 2:52am    
check my answer

1 solution

Go to Your form .Designer.cs file and check for DataPropertyName given for each column, you need to give below for each column

C#
Host-Name
Ip_Address
User_Name
Password
 
Share this answer
 
Comments
sovit agarwal 20-May-14 3:22am    
That was simply awesome Damith
Thanks a lot!!
sovit agarwal 20-May-14 5:43am    
Hi Damith!!
Although the problem was solved but this led to another problem
The number of rows i am adding to this , that many number of columns are also getting alongside it
DamithSL 20-May-14 5:49am    
you can do the same in your form designer view, select the grid in designer view and click on small allow in top right corner of the grid, then you can click edit columns link.<br>
in the edit column window you can add remove columns and also you can change the DataPropertyName of each column. ply with it :-)
for each column you can add controls like textbox column or label etc.. select the control and set the DataPropertyName as one of column name like Host-Name
sovit agarwal 20-May-14 5:58am    
Thanks Damith !!
Can u also help me with this ...
http://www.codeproject.com/Questions/775484/How-Do-I-Disconnect-A-Server-Which-Is-In-A-Tcplist

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



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