Solved

DataSet to fit DataGrid

Posted on 2006-07-19
7
329 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
  • 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

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

948 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

22 Experts available now in Live!

Get 1:1 Help Now