Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on Component One grid

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
US
I'm trying out True DB Grid Pro for .NET and I am trying to set the color of all of the cells in a row. I am able to do this at load time by using this code; dbGrid_FetchRowStyledbGrid.FetchRowStyle.

What I want to do is AFTER the grid is loaded and displayed, and the user presses a button, row 2, or whatever needs
to have it's backcolor turn red. This is independant of the selected row.
Is this possible with VB.NET code?

I know how to do it when the grid is being loaded.

What I need is a way to change the colors AFTER the grid has been loaded from the database.

We use the grid in our 9-11 software package. All of the officer's calls are placed into the database and displayed on your grid. If the officer is on the call too long without calling in, an alarm will sound on the console and his record in the grid will have to flash red.

So I need a way to change the back color of a row after the data has been loaded, and while there is no database activity.

I can't seem to get to the row object, or the cell object either.

Thanks
 
Code:
    Me.C1FlexGrid3.Rows(10).Style() = Me.C1FlexGrid3.Rows(10).StyleNew()
    If Me.C1FlexGrid3.Rows(10).Style().BackColor.Equals(Color.White) Then
      Me.C1FlexGrid3.Rows(10).Style().BackColor = Color.Red
    Else
      Me.C1FlexGrid3.Rows(10).Style().BackColor = Color.White
    End If

-Rick

----------------------
 
Code does not work.
This is for the flex grid. Am I using the wrong control?
I'm using True DBGrid.
 
Thank you so much. I can wait a bit. I'm going out for lunch.

BTW: Is flex grid better? Can I display icons in it? Can it do multo rows? I don't need in cell editing.
 
I haven't had much experience with the True grid. So I can't say one is 'better' than the other. Expecially because they likely do different things. Is a Hammer 'better' then a screwdriver?

Each control is a tool, there are some jobs a tool can do very well, some jobs a tool can't do very well, and some jobs that just shouldn't be done with a tool. Picking the right tool for the job is part of the design, and usinging the correct tool can save you loads of time in developement.

That being said, I love the C1.flex grid. I use it mostly for displaying large amounts of related data. Often in search returns.

Another inhouse project the developers used a C1.flex grid in tree view format to replace the standard microsoft TreeView control. By using the Flex grid they managed to avoid several issues they had run into with the TreeView. Had they used the Flexgrid from the get go, they would have saved about 20 hours dev time on trying to correct issues with the treeview, and the redesign time of implimenting the flexgrid.

But if the tool you are using doesn't do what you need it to, take a quick look arround and see if there is a tool that does do what you need. A $100 license is much cheaper then a week's worth of dev time.




Back to the mater at hand, I'm not sure what you mean by multo rows, but I know the Flexgrid can handle Icons.

-Rick

----------------------
 
Sorry, that should have been multi rows. Where you have 30 rows loaded and there is a plus sign on the left side where toy can close the group down to 4 rows. Then they have plus signs ther instead for opening them up again.
The True grid does this.

I just got a trial of the flexgrid. It looks very cool. I want our company to get their whole suite.
 
Just a suggestion about getting the C1 suit. Check out the Microsoft .Net Resource Kit. From what I've heard there is a license for the c1 tools included at a fraction of the cost.

-Rick

----------------------
 
After playing with the true db grid a bit, I'm not seeing an easy way to do what you are looking for (flashing a row's back color). It may be possible, but I am not seeing an easy way.

It is possible to flash the background color of the current selection, but I wasn't finding an easy way to select a row at runtime (other then with the mouse)

-Rick

----------------------
 
I have used True DBGrid quite extensively, and what you are after should be feasible. When you talk about the row object, you need to think more in terms of the underlying Datasource when working with this grid. ie the datarow.

I have successfully created a rowcheking event in my DGGrid class, which I use to conditionally check the datarow, while the grid is populated. One of the parameters passed to this event is the Datarow of the grid itself, which you have to get a handle to use DataRowView.

Once you have this in place, it is very easy to to colour either individual rows or cells.

Please post back if you need more help with this, and I'll try and provide some sample code, extracted from my now rather top heavy class code.



Sweep
...if it works dont mess with it
 
Rick

This is difficult to summarise, but I'll take a shot at it. Firstly my datagrid class always works from a dataview. If I want the entire table, I just use table.defaultview.

I have a property to get the current Datarow of the selected grid line as follows
Code:
Public ReadOnly Property GridRow() As DataRow
        Get
            Dim dr As DataRow
            If Not Me.oDataSource Is Nothing Then
                If grid1.Row < 0 Then Return Nothing
                Dim drv As DataRowView
                drv = Me.oDataView(grid1.Row)
                dr = drv.Row
            End If
            Return dr
        End Get
    End Property

Then in the fetch row style of the grid I have the following code, which raises an Event (CheckingRowValue), which is used to condtionally check rows against certain conditions. If a condition is met and I want to colour a row, I set the iBackColor and iForeColor variables accordingly
Code:
    Public Event CheckingRowValue(ByVal sender As Object, ByVal r As DataRow, ByRef iForeColor As Integer, ByRef iBackColor As Integer, ByRef bBold As Boolean)

 Private Sub grid1_FetchRowStyle(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs) Handles grid1.FetchRowStyle

        Dim iForeColor As Integer = 0
        Dim iBackColor As Integer = 0
        Dim bBold As Boolean = False

        Dim drv As DataRowView = Me.oDataView(e.Row)
        Dim r As DataRow = drv.Row

        RaiseEvent CheckingRowValue(sender, r, iForeColor, iBackColor, bBold)

        Me.zPaintRows(e, iForeColor, iBackColor, bBold)

    End Sub

All the zPaintRows method does is to apply the colors based on the integer values sent to it.

Going back to the original post, I would assume the grid would have to be repainted every so often using a timer event, and if each datarow had a datetime field to compare against the current datetime, then the row colouring should be very achievable.



Sweep
...if it works dont mess with it
 
After messing with the flex grid, I may use this one too.

I'm going to be testing for features of both over the next couple of days.
 
Sweep, I'm assuming this is a custom control that inherits from the trueDBGrid, right? Some pretty snazzy code work! Question though, how does zPaintRows know which rows to paint? or does it just paint the visible rows?

-Rick

----------------------
 
What about when I do web pages? Do I use the c1 grid, or do i use M$'s grid?
 
Rick

It knows which row to colour because internally it is processing that row at the time. It will only apply paint if either iForeColor or iBackColor is non zero.

This is the beauty of it. The checkingrowvalue can work from the underlying data (each datarow), without any knowledge of which rowindex of the grid it is on

Just so its clearer, and that zPaintrows does nothing clever at all, Ive posted the code for that too.
Code:
 Private Sub zPaintRows(ByVal e As C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs, _
       ByVal iForeColor As Integer, _
        ByVal iBackColor As Integer, _
        ByVal bBold As Boolean)

        Select Case iForeColor
            Case -1
                e.CellStyle.ForeColor = System.Drawing.Color.WhiteSmoke
            Case 1
                e.CellStyle.ForeColor = System.Drawing.Color.Red
            Case 2
                e.CellStyle.ForeColor = System.Drawing.Color.Green
            Case 3
                e.CellStyle.ForeColor = System.Drawing.Color.Blue
            Case 10
                e.CellStyle.ForeColor = System.Drawing.Color.White
        End Select

        Select Case iBackColor
            Case -1
                e.CellStyle.BackColor = System.Drawing.Color.WhiteSmoke
            Case 1
                e.CellStyle.BackColor = System.Drawing.Color.LightYellow
            Case 2
                e.CellStyle.BackColor = System.Drawing.Color.Honeydew
            Case 3
                e.CellStyle.BackColor = System.Drawing.Color.AliceBlue
            Case 4
                e.CellStyle.BackColor = System.Drawing.Color.Red
            Case 5
                e.CellStyle.BackColor = System.Drawing.Color.CornflowerBlue
            Case 6
                e.CellStyle.BackColor = System.Drawing.Color.LimeGreen
        End Select

        If bBold Then
            e.CellStyle.Font = New Font(Me.Font, FontStyle.Bold)
        End If

    End Sub







Sweep
...if it works dont mess with it
 
Hey sweep, you're doing all this on grid1_FetchRowStyle, right?
But what if I want to change the color of a row without reloading the grid? I can't do a refresh either because someone may be scrolling the grid at the time.
I need to make a row blink, or just change the backcolor to red or yellow.
 
bigfoot

I fail to see how else you can do this without using fetchrowstyle. The only other way is to use a grid where you have complete flexibility over the rows/cells.

However I ran a test on my grid class, whereby all I did was to add a button to a form which simply set an integer field in the currently selected grid row to 1.

I also placed a line of code in my CHeckingRowValue Event, which simply said

Code:
if r("testfield")=1 then iBackColor=5
and in the code behind a button I added to my form
Code:
dt.zMoveFirst() 'move to first record in grid
Dim r As DataRow = dt.oCurrentDataRow
r("testfield") = 1

I did not rebuild or refresh the grid, and still the row was highlighted. I also updated a row which was not the current grid row, and that also was highlighted.

Now this behaviour although beneficial, has me absolutely flummoxed to how it works. All I am doing is using a button to change a datarow in the underlying data, and yet the grid somehow senses the change and updates itself.




Sweep
...if it works dont mess with it
 
I think I'm on to something here.

I did not know I could refresh one row at a time so here is how I think I'm gonna do it.

Code:
Private Sub dbGrid_FetchRowStyle(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs) Handles dbGrid.FetchRowStyle
	e.CellStyle.ForeColor = GetVBColor(Str(dbGrid(e.Row, 7)))
	If bAlarmSet = True Then
		e.CellStyle.BackColor = Color.Salmon
                bAlarmSet =False
	End If

Now in my sub that causes the "alarm" that changes the colors in the grid I put:
Code:
bAlarmSet = True
dbGrid.RefreshRow(0) ' This is the row that I set the alarm in...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top