Solved

Using the datagrid (winforms) + binding to xml?

Posted on 2006-06-19
4
599 Views
Last Modified: 2008-01-09
Hi there,

Can anybody tell me if its possible to have ROW HEADERS rather than column headers, i can't seem to find it. I need to add these manually

Also is it possible to bind it to an XML file i have?

The xml file contains other data also.... so i would need to exclude that...

The information that i want to display doesn't really need to binded to a database ... so is it possible to add to the grid in code?

Any help or information would be really appreciated

Thanks in advance

Ian
0
Comment
Question by:ianinspain
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 16933527
Hi ianinspain,

You need to create an empty dataset, then use the .LoadXML("Path\filename.xml") method to load the xml data into the dataset, this can then be bound to the grid to display. You can modify the dataset as much as you like in order to remove some of the information, it will of course not be reflected in the file unless you use .WriteXML() to write it back.

Tim Cottee
0
 

Author Comment

by:ianinspain
ID: 16933614
wow ... thanks thats great! I will take a look now..

Is it also possible to add ROW headers .. like descriptions i.e.


Total        89
Pending    20
Awaiting   11

etd.. i.e the row headers are descriptions for each row...

Do i have to force this information into the xml file to get it to print it .... ??
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 16933684
ianinspain,

Yes you would, there is no RowHeaders collection like the ColumnHeaders so you would need to manipulate the data to do this in some fashion I am afraid.

Tim
0
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 250 total points
ID: 16934080
that will work for datagridview. I did not try for the datagrid

Private Sub dataGridView1_RowPostPaint(ByVal sender As Object, _
  ByVal e As DataGridViewRowPostPaintEventArgs) _
    Handles dataGridView1.RowPostPaint

  ' Paint the row number on the row header.
  ' The using statement automatically disposes the brush.

Using b As SolidBrush = _
    New SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor)

  e.Graphics.DrawString( _
    e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentUICulture), _
    e.CellStyle.Font, _
    b, _
    e.RowBounds.Location.X + 20, _
    e.RowBounds.Location.Y + 4)

End Using

End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now