DataGridViewColumn.DisplayIndex

  • Thread starter c j anderson, mcp
  • Start date
C

c j anderson, mcp

Synopsis: DataGridViewColumn reorder does not update display, but a
repopulation of underlying dataset does...

I must be missing something obvious. I have a scenario where the
underlying XML data schema may change and need to populate a datagrid
with the result. The row data will always consist of one simple string
element with multiple attributes -- the number and names of the
attributes may change. When the data is read in by the app, the
attributes of the element become the first columns of the datagridview
and the text of the element becomes the last column -- this is the
opposite of what is desired.

So, I have undertaken to re-order the data. the issue is that the first
re-order attempt does not work. if the full routine is run a second
time, it produces the correct result as far as column order...

In testing, the Invalidate and Refresh methods of the DataGridView

'****Code from inside a Button.Click handler***
dset = New DataSet()
dset.ReadXmlSchema(My.Application.CurrentDirectory +
"\Keywords.xsd")

Dim xr As XmlReader
Dim xrs As New XmlReaderSettings()
xrs.IgnoreWhitespace = True
xrs.XsdValidate = True
AddHandler xrs.ValidationEventHandler, AddressOf ValidationHandler

xrs.Schemas.Add(Nothing, New
XmlTextReader(My.Application.CurrentDirectory + "\Keywords.xsd"))
xdd = New XmlDataDocument(dset)
xr = XmlReader.Create(txtKeywordsFile.Text, xrs)
xdd.Load(xr)

dgrdvwKeywords.DataSource = dset
dgrdvwKeywords.DataMember = "keyword"

'reorder columns so that keyword is first
For Each col As DataGridViewColumn In dgrdvwKeywords.Columns
If (col.Name = "keyword_text") Then
col.Name = "keyword"
col.DisplayIndex = 0
Else
col.DisplayIndex += 1
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top