473,804 Members | 3,958 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 5017
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
9707
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
9585
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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...
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
3823
muto222
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.