473,471 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how do highlight a specific cell in a winforms .net datagrid?

The datagrid has a tablestyle applied to it, and there
are DataGridTextBoxColumn and each DataGridTextBoxColumn
has an array of DataGridTextBox objects.

Private Sub highlight(ByVal str As String)
Dim myTextBoxcolumn As DataGridTextBoxColumn
Dim myTextBox As DataGridTextBox

'loop through the cells of the datagrid, searching
for the string

For c As Integer = 0 To
DataGrid1.VisibleColumnCount - 1
For r As Integer = 0 To
DataGrid1.VisibleRowCount - 1

'if the content of the sell matches the
str, we want to highlight it.
If CType(DataGrid1.Item(r, c), String) =
str Then

myTextBoxcolumn = _
CType(DataGrid1.TableStyles
(0).GridColumnStyles(c), DataGridTextBoxColumn)

myTextBox = CType
(myTextBoxcolumn.TextBox, DataGridTextBox)
myTextBox.BackColor = Color.Red
myTextBox.ForeColor = Color.Blue
End If
Next
Next
End Sub

This routine highlights the entire column, not just a
single cell, moreover, you can only see the highlighting
when the cell is selected (has the focus). Is there
anyway to have the cell highlighted, even when it is not
selected? It seems that the datagrid should be capable of
this, but I cannot find any objects which expose the
necessary properties...

I can highlight an entire row, or a column, but setting
the background color on a single cell, or multiple cells
on different rows and different columns still eludes me.

If any gurus would help, I would be very appreciative.

Kind Regards,
Greg
Jul 19 '05 #1
1 4961
AnurRS
1 New Member
hello,

i am able to highlight the cell only but the same problem problem as yours i am also getting. i.e. when the user clicks the other cell of the datagrid, then the previously highlighted color of the cell is not preserved. i want to make highlighting that cell despite of user clciking on the other cell.

have u done anything on this. i am sending u the code that can highlight the cell only.

for (int row = 0; row < totalRows - 1; row++)

{
for (int col = 0; col < totalCols; col++)
{

string result= ,,,,,,,,// u can call the function of word searching
if (result != null)
{
int index = ((string)<datagridname>[col, row].Value).IndexOf(result);
int length = result.Length;

dgsource[col, row].Selected = true;

dgsource[col, row].Style.SelectionBackColor = color name;

}

}
}
Jun 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Graham Y | last post by:
I have a datagrid, populated via a SQL dataset, and I want the user to select a row by clicking on it and then using the value in the first cell as my key for my next query. Using...
2
by: Nanda | last post by:
Hi all, while editing a datagrid cell, if i press Enter key focus goes to the next row, instead that i would like to have focus on next cell, how can i obtain this. Thanks & Regards, Nanda
1
by: Michael Ramey | last post by:
I'm using the following code to highlight the current row: private void Datagrid1_CurrentCellChanged(object sender, System.EventArgs e) { DataGrid1.Select(DataGrid1.CurrentRowIndex); } The...
4
by: mike | last post by:
I'm trying to highlight a specific row in a datagrid who's contition matches ..text = "Dawn" i've been playing with the code below without much luck, is there a foreach loop i could do, like (...
2
by: Ben Bloom | last post by:
I've got a datagrid with a column named "Type". If cells in this column contain "Error" I would like to highlight them (say - turn the text red, or the background red.) How do I do this? Is...
2
by: Geraldine Hobley | last post by:
Hello I have a datagrid, called MyDataGrid and I wish to put the focus on a particular cell in order that the user to highlight the fact that the user needs to enter a value in this cell, e.g. I put...
1
by: Don | last post by:
George Shepherd's great Windows Forms FAQ has this article about creating a datagrid with no active cell: http://www.syncfusion.com/faq/winforms/search/856.asp Unfortunately, this only works...
0
by: Gerg | last post by:
The datagrid has a tablestyle applied to it, and there are DataGridTextBoxColumn and each DataGridTextBoxColumn has an array of DataGridTextBox objects. Private Sub highlight(ByVal str As...
2
by: Sharon | last post by:
I want put into my DataGrid different control types in the same column. For example: Column 1, row 0 ==> TextBox Column 1, row 2 ==> CheckBox Column 1, row 2 ==> ComboBox etc... As I see, I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
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
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.