Solved

DataSet to fit DataGrid

Posted on 2006-07-19
7
333 Views
Last Modified: 2008-03-06
Hi,

I load a dataset into a datagrid from XML file. The file loads correctly but its display doesn't completely fit the datagrid: there is a grey space on the right. I want to get rid of that grey space so that the data columns are expanded to use all of the space available. The first column, where you select the rows, shouldn't be expanded. How do I achieve this? I looked into DataGridTableStyle class but I couldn't figure out how to use it; it seems to repeat the same methods from DataGrid class. Thanks for your help.

 Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        LoadXMLData()
    End Sub    

    Private Sub LoadXMLData()
        ds = New DataSet
        ds.ReadXml("c:\rules.xml")
        xmlRules.SetDataBinding(ds, "rule")
        tbl = ds.Tables(0)
    End Sub

XML file example
========

<?xml version="1.0"?>
<folder-rules>
  <rule>
    <variable>m_EDSTYPCD</variable>
    <value>P</value>
    <destination>Facilities</destination>
    <default>Blah</default>
    <function>PrintGreeting</function>
    <param1>Hello</param1>
    <param2>World</param2>
    <level>1</level>
  </rule>
</folder-rules>
0
Comment
Question by:njava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 1

Author Comment

by:njava
ID: 17140604
xmlRules is a DataGrid
ds is a DataSet
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17141403
1) Define a DataGridTableStyle
2) Specify each column type as DataGridTextBoxColumn, DataGridBoolColumn, etc.
3) Define the column widths as a percent of ClientSize.Width for the entire DataGrid.

Bob
0
 
LVL 1

Author Comment

by:njava
ID: 17141651
Would it be possible to provide an example?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 50 total points
ID: 17141708
Example:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21876101.html

Set column widths like this:

Column 1:  DataGrid1.ClientSize.Width * .25
Column 2:  DataGrid1.ClientSize.Width * .25
Column 3:  DataGrid1.ClientSize.Width * .25
Column 4:  DataGrid1.ClientSize.Width * .10
Column 5:  DataGrid1.ClientSize.Width * .5
Column 6:  DataGrid1.ClientSize.Width * .20

The total needs to be 1.00 or 100% of the width.

Bob
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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