473,804 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ 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 DataGridTextBox Column and each DataGridTextBox Column
has an array of DataGridTextBox objects.

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

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

For c As Integer = 0 To
DataGrid1.Visib leColumnCount - 1
For r As Integer = 0 To
DataGrid1.Visib leRowCount - 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).GridColumnS tyles(c), DataGridTextBox Column)

myTextBox = CType
(myTextBoxcolum n.TextBox, DataGridTextBox )
myTextBox.BackC olor = Color.Red
myTextBox.ForeC olor = 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 5016
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)<datag ridname>[col, row].Value).IndexOf (result);
int length = result.Length;

dgsource[col, row].Selected = true;

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

}

}
}
Jun 15 '06 #2

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

Similar topics

2
1991
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 CurrentCellChanged works unless I want the row which has a cell selected and I click on that cell, obvious answer click another cell in that row, but I have to code for stupid users! I tried the click event but that didn't work, maybe I was doing something wrong....
2
12998
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
5282
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 entire row is selected, but the cell with cursor in it, shows the grid value as selected. The looks strange. Is there a way to eliminate the cell selection?
4
9677
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 ( foreach(datarows in datagrid) check if the first cell in the row contains Dawn if so highlight the row. )
2
1720
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 there an example out there somewhere? Thanks! -- to reply, remove .s.p.a.m. from email
2
1615
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 the message up "Please enter an order number" I then wish to highlight the column MyDataGrid(0,1), but I can't find out how to do this Many thanx in advance Geri
1
1529
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 properly for datagrids that are not ReadOnly (i.e. a row will become unhighlighted if you click the same cell twice). Has anyone discovered a way to have a read-only datagrid with no active cell?
0
297
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 String) Dim myTextBoxcolumn As DataGridTextBoxColumn Dim myTextBox As DataGridTextBox 'loop through the cells of the datagrid, searching for the string
2
7426
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 can hold only one kind of sell type in the same column. is there a way to do it anyway.
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6854
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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 we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.