473,473 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Refreshing grid

65 New Member
How can i refresh datagrid in vb.net.
I want to display color in one cell in grid but when it loads first time it is working here is my code
Expand|Select|Wrap|Line Numbers
  1. Public Class Dialog_Colorazione
  2.     Const YEAR_START As Integer = 2005
  3.     'function to fill the combo with year
  4.     Private Sub LoadComboBoxes()
  5.         cboYear.Items.Clear()
  6.         cboYear.SelectedIndex = -1
  7.         Dim i As Integer
  8.         For i = Date.Today.Year To YEAR_START Step -1
  9.             cboYear.Items.Add(i.ToString())
  10.         Next
  11.         cboYear.SelectedIndex = 0
  12.         ' loadcolor(cboYear.SelectedItem)
  13.     End Sub
  14.  
  15.     Private Sub Dialog_Colorazione_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  16.         'Me.Close()
  17.     End Sub
  18.     'till here function to fill the combo with year
  19.  
  20.    Private Sub Dialog_Colorazione_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  21.         'calling functions to fill the combo and display the color details
  22.         'cboYear.SelectedText = Today.Year
  23.  
  24.         LoadComboBoxes()
  25.         ' loadcolor(cboYear.SelectedItem)
  26.         'cboYear.SelectedIndex = 1
  27.         dgvFatturato.Refresh()
  28.  
  29.     End Sub
  30.  
  31.     'function the collect and fill the grid with the colors in the selected year
  32.     Public Function loadcolor(ByVal year As Integer)
  33.         Dim currentyear As Integer = Today.Year
  34.         Using connection As New OleDbConnection(My.Settings.BCS_ACCConnectionString & ";Jet OLEDB:Database Password=" & Costanti.strAccessDbPassword)
  35.  
  36.             connection.Open()
  37.  
  38.             Dim adpt As New OleDb.OleDbDataAdapter("SELECT RefYear,LowRange,UpRange,ColorName FROM ACC_COLORI_FATTURATO WHERE RefYear=" & year & "", connection)
  39.  
  40.             Dim ds As New DataTable
  41.  
  42.             adpt.Fill(ds)
  43.  
  44.             'added on 08/12/2007 to display color in the datagrid
  45.             If ds Is Nothing Or ds.Rows.Count = 0 Then
  46.                 ShowMessage("Nessun dato per i criteri selezionati")
  47.                 dgvFatturato.Visible = False
  48.             Else
  49.                 dgvFatturato.DataSource = Nothing
  50.                 dgvFatturato.Visible = True
  51.                 dgvFatturato.DataSource = ds
  52.  
  53.                 ds.Columns(0).ColumnName = "Anno"
  54.                 ds.Columns(1).ColumnName = "Maggiore da"
  55.                 ds.Columns(2).ColumnName = "Minore da"
  56.                 ds.Columns(3).ColumnName = "Colore"
  57.                 ' ds.Columns(4).ColumnName = "ID colore" 'commended on 11/01/2008 for hiding the coloumn
  58.  
  59.                 'Added on 11/01/2008
  60.                 ' Dim year1 As Integer = cboYear.SelectedItem
  61.                 Using connection1 As New OleDbConnection(My.Settings.BCS_ACCConnectionString & ";Jet OLEDB:Database Password=" & Costanti.strAccessDbPassword)
  62.                     connection1.Open()
  63.                     Dim ds1 As New DataTable
  64.                     Dim adpt1 As New OleDbDataAdapter("select color from ACC_COLORI_FATTURATO WHERE RefYear=" & year & "", connection)
  65.                     adpt1.Fill(ds1)
  66.                     If dgvFatturato.RowCount > 0 And ds1.Rows.Count > 0 Then
  67.                         For Each row As DataGridViewRow In dgvFatturato.Rows
  68.                             ' For i As Integer = 0 To ds1.Rows.Count - 1
  69.                             Dim colorn As Integer = ds1.Rows(row.Index).Item(0)
  70.                             row.Cells(3).Style.BackColor = Color.FromArgb(255, Color.FromArgb(CType(colorn, Int32)))
  71.                         Next
  72.                     End If
  73.                     connection1.Close()
  74.                 End Using
  75.                 ''Till here
  76.  
  77.             End If
  78.             'Till here added on 08/12/2007  to display color in the datagrid
  79.  
  80.             connection.Close()
  81.         End Using
  82.  
  83.     End Function
  84.     'till here function the collect and fill the grid with the colors in the selected year
  85.  
  86.     'function to convert decimal value to hexadecimal
  87.     Private Function DeciamlToHexadeciaml(ByVal number As Integer) As String
  88.         Dim hexvalues As String() = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
  89.         Dim result As String = Nothing
  90.         Dim final As String = Nothing
  91.         Dim div As Integer = 0
  92.         Dim rem1 As Integer
  93.  
  94.         While True
  95.             rem1 = (number Mod 16)
  96.             result += hexvalues(rem1).ToString()
  97.  
  98.             If number < 16 Then
  99.                 Exit While
  100.             End If
  101.  
  102.             number = (number / 16)
  103.         End While
  104.         For i As Integer = (result.Length - 1) To 0 Step -1
  105.  
  106.             final += result(i)
  107.         Next
  108.  
  109.         Return final
  110.     End Function
  111.     'till here function to convert decimal value to hexadecimal
  112.  
  113.     'to collect and display the color information on change of the combo
  114.     Private Sub cboYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboYear.SelectedIndexChanged
  115.         loadcolor(cboYear.SelectedItem)
  116.     End Sub
  117.     'till here to collect and display the color information on change of the combo
  118.  
  119.     Protected Sub ShowMessage(ByVal message As String)
  120.         ToolStripStatusLabel2.Text = message
  121.     End Sub
  122.  
  123.     Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  124.         Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  125.         Me.Close()
  126.     End Sub
  127.     Private Sub dgvFatturato_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvFatturato.CellContentClick
  128.  
  129.     End Sub
  130.  
  131.     Protected Overrides Sub Finalize()
  132.         MyBase.Finalize()
  133.     End Sub
  134. End Class
  135.  


Thanks....
Jan 11 '08 #1
3 1643
Frinavale
9,735 Recognized Expert Moderator Expert
After reading your question, I got the impression that you were having problems changing the colour of your GridView's cells when the GridView is First Loaded.

I suggest changing the cell's colours in the method that handles your GridView's RowDataBound event.

EG:
Expand|Select|Wrap|Line Numbers
  1. Protected Sub dgvFatturato_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV_SearchResults.RowDataBound
  2.        For i As Integer = 0 to e.Row.Cells.Count -1
  3.             e.Row.Cells(i).Style.BackColor = Color.FromArgb(255, Color.FromArgb(CType(colorn, Int32)))
  4.         Next
  5.  
  6. End Sub
  7.  
I'm not sure if this is what your asking for though...your code suggests that you are dealing with selecting colours in your GridView...

-Frinny
Jan 11 '08 #2
veenna
65 New Member
Thank you.. for your replay..


My problem is :
When the page loads first time it display color in the grid. But after that it is not displaying color on page load and in dropdown selected index change i am calling the same function there it is working fine.
Jan 12 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Thank you.. for your replay..


My problem is :
When the page loads first time it display color in the grid. But after that it is not displaying color on page load and in dropdown selected index change i am calling the same function there it is working fine.
Something else (after your Page_Load) may be setting the colour to something else...Check that this is not the case.
Jan 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: James Evans | last post by:
I am having some problems with my vb.net\asp.net\sql 2000 app. Two web forms. All stored procs for data access. One form does inserts and delets - no problems. The other form does the updates. The...
0
by: serge calderara | last post by:
Dear all, I am develpping a .NET vb application fro 2000 and XP. I have actually an Collection list of Type, where type have 4 variables inside This collection list can be really long. I then...
1
by: Avi | last post by:
Hi Experts, I would like to display the latest 500 events from a table which contains over a million records. The speed of insertion is about 25 a second. How can I display it and refresh the...
0
by: AinO | last post by:
Hi, I implemented a way (googling) to change a row's height in the grid from the code. It works fine, but the datagrid needs to be in read only mode ; for now this is ok. However, to repaint...
4
by: Kenneth | last post by:
Hi, I have two forms, parentForm and childForm. parentForm has a button(btn1) and a grid. childForm has a couple of textboxes and a button. The button on parentForm opens a new window of...
1
by: Tom | last post by:
I have an ASP.NET web page coded in VB.NET (2003). That web page has a dropdown box on it which is loaded during the page_load event. When the user drops this down and selects a data item, the...
6
by: MattB | last post by:
I have a page header that I made as a user control (ascx) that I drop on every page in my application. The application is an eCommerce application and I have a total for items in the cart on the...
0
by: kevin_giles78 | last post by:
hello everyone. There may be a better way to do what I want but please bear with me as I need a simple explanation of how to do something with a data grid. I have a grid showing a status in a...
1
by: Steve S | last post by:
Hey guys, I'm stuck with using a GridBagSizer (wxPython) in a GUI Dialog and am having a frustrating time with refreshing it properly. Essentially, I've got to refresh the contents of the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.