Click here to Skip to main content
15,844,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I created this code (I'm only showing part of it) where I read an XML file and display it in a datagridView. In this, the attribute (table:style-name="ce215") changes the background of the single cell of the datagridview to yellow, but I can't understand how to do it... thanks so much for the help!!

A part of XML:
XML
<table:table>
				<table:table-row table:style-name="ro1">
					<table:table-cell table:style-name="ce215" 
                    office:value-type="string" calcext:value-type="string">
						<text:p>LDP</text:p>
					</table:table-cell>
				</table:table-row>
			</table:table>


What I have tried:

VB
If nodeList IsNot Nothing Then

    For Each sheet As XmlNode In nodeList.SelectNodes("table:table", nsMgr)

        sheetName(tabella) = sheet.Attributes("table:name").Value

        For Each rowNode As XmlNode _
               In sheet.SelectNodes("table:table-row", nsMgr)
            Dim rowData As New List(Of String)()
            For Each cellNode As XmlNode _
                In rowNode.SelectNodes("table:table-cell", nsMgr)

                Dim colors As String = cellNode.Attributes_
                                       ("table:style-name").Value
                ' If colors = "ce215" Then
                ' do something like change background color = Color.Yellow
                'End If

                rowData.Add(cellNode.InnerText)

            Next

            dataSet.Tables("Tab" & tab).Rows.Add(rowData.ToArray())
        Next
        tab += 1

    Next
Posted
Updated 3-Oct-23 7:36am
v2

1 solution

This is a common question with many answers on the internet. A simple Google search will give you many solutions: winform datagridview cell background color - Google Search[^]. Also there are related questions with solutions to the right of this one.

Here is an example of one Question with a Solution from here on Code Project: Change background color of cells in DataGridView C#[^].

Lastly, in a previous solution to one of your many other questions, I showed you how to use ChatGPT to convert C# to VB. So if you find a C# solution that you want to use, you know how to convert the code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900