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 -
Public Class Dialog_Colorazione
-
Const YEAR_START As Integer = 2005
-
'function to fill the combo with year
-
Private Sub LoadComboBoxes()
-
cboYear.Items.Clear()
-
cboYear.SelectedIndex = -1
-
Dim i As Integer
-
For i = Date.Today.Year To YEAR_START Step -1
-
cboYear.Items.Add(i.ToString())
-
Next
-
cboYear.SelectedIndex = 0
-
' loadcolor(cboYear.SelectedItem)
-
End Sub
-
-
Private Sub Dialog_Colorazione_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
-
'Me.Close()
-
End Sub
-
'till here function to fill the combo with year
-
-
Private Sub Dialog_Colorazione_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
'calling functions to fill the combo and display the color details
-
'cboYear.SelectedText = Today.Year
-
-
LoadComboBoxes()
-
' loadcolor(cboYear.SelectedItem)
-
'cboYear.SelectedIndex = 1
-
dgvFatturato.Refresh()
-
-
End Sub
-
-
'function the collect and fill the grid with the colors in the selected year
-
Public Function loadcolor(ByVal year As Integer)
-
Dim currentyear As Integer = Today.Year
-
Using connection As New OleDbConnection(My.Settings.BCS_ACCConnectionString & ";Jet OLEDB:Database Password=" & Costanti.strAccessDbPassword)
-
-
connection.Open()
-
-
Dim adpt As New OleDb.OleDbDataAdapter("SELECT RefYear,LowRange,UpRange,ColorName FROM ACC_COLORI_FATTURATO WHERE RefYear=" & year & "", connection)
-
-
Dim ds As New DataTable
-
-
adpt.Fill(ds)
-
-
'added on 08/12/2007 to display color in the datagrid
-
If ds Is Nothing Or ds.Rows.Count = 0 Then
-
ShowMessage("Nessun dato per i criteri selezionati")
-
dgvFatturato.Visible = False
-
Else
-
dgvFatturato.DataSource = Nothing
-
dgvFatturato.Visible = True
-
dgvFatturato.DataSource = ds
-
-
ds.Columns(0).ColumnName = "Anno"
-
ds.Columns(1).ColumnName = "Maggiore da"
-
ds.Columns(2).ColumnName = "Minore da"
-
ds.Columns(3).ColumnName = "Colore"
-
' ds.Columns(4).ColumnName = "ID colore" 'commended on 11/01/2008 for hiding the coloumn
-
-
'Added on 11/01/2008
-
' Dim year1 As Integer = cboYear.SelectedItem
-
Using connection1 As New OleDbConnection(My.Settings.BCS_ACCConnectionString & ";Jet OLEDB:Database Password=" & Costanti.strAccessDbPassword)
-
connection1.Open()
-
Dim ds1 As New DataTable
-
Dim adpt1 As New OleDbDataAdapter("select color from ACC_COLORI_FATTURATO WHERE RefYear=" & year & "", connection)
-
adpt1.Fill(ds1)
-
If dgvFatturato.RowCount > 0 And ds1.Rows.Count > 0 Then
-
For Each row As DataGridViewRow In dgvFatturato.Rows
-
' For i As Integer = 0 To ds1.Rows.Count - 1
-
Dim colorn As Integer = ds1.Rows(row.Index).Item(0)
-
row.Cells(3).Style.BackColor = Color.FromArgb(255, Color.FromArgb(CType(colorn, Int32)))
-
Next
-
End If
-
connection1.Close()
-
End Using
-
''Till here
-
-
End If
-
'Till here added on 08/12/2007 to display color in the datagrid
-
-
connection.Close()
-
End Using
-
-
End Function
-
'till here function the collect and fill the grid with the colors in the selected year
-
-
'function to convert decimal value to hexadecimal
-
Private Function DeciamlToHexadeciaml(ByVal number As Integer) As String
-
Dim hexvalues As String() = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
-
Dim result As String = Nothing
-
Dim final As String = Nothing
-
Dim div As Integer = 0
-
Dim rem1 As Integer
-
-
While True
-
rem1 = (number Mod 16)
-
result += hexvalues(rem1).ToString()
-
-
If number < 16 Then
-
Exit While
-
End If
-
-
number = (number / 16)
-
End While
-
For i As Integer = (result.Length - 1) To 0 Step -1
-
-
final += result(i)
-
Next
-
-
Return final
-
End Function
-
'till here function to convert decimal value to hexadecimal
-
-
'to collect and display the color information on change of the combo
-
Private Sub cboYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboYear.SelectedIndexChanged
-
loadcolor(cboYear.SelectedItem)
-
End Sub
-
'till here to collect and display the color information on change of the combo
-
-
Protected Sub ShowMessage(ByVal message As String)
-
ToolStripStatusLabel2.Text = message
-
End Sub
-
-
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
-
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
-
Me.Close()
-
End Sub
-
Private Sub dgvFatturato_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvFatturato.CellContentClick
-
-
End Sub
-
-
Protected Overrides Sub Finalize()
-
MyBase.Finalize()
-
End Sub
-
End Class
-
Thanks....
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: -
Protected Sub dgvFatturato_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV_SearchResults.RowDataBound
-
For i As Integer = 0 to e.Row.Cells.Count -1
-
e.Row.Cells(i).Style.BackColor = Color.FromArgb(255, Color.FromArgb(CType(colorn, Int32)))
-
Next
-
-
End Sub
-
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
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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 ...
| |