Solved

DataSet to fit DataGrid

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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…

757 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

21 Experts available now in Live!

Get 1:1 Help Now