473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 4956
AnurRS
1
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.