How can I hihglight the whole row of DataGrid ?

S

Serg Matvienko

Hi everybody,

My dataGrid is "for read" only.How can I hihglight the whole row of DataGrid
when I am navigating through rows? Now I can see only a small triangle on
the right side of dataGrid moving.

Thanks a lot in advance,
Serg
 
M

Mohamoss

Hi Serg
You can achieve this function by selecting the current row index while
navigations . you will be using the select function of the datagrid passing
the it the current row selected. This should be implemented in the
navigation event of your grid. Here is a snippet
private void dataGrid1_Navigate(object sender,

System.Windows.Forms.NavigateEventArgs ne)
{
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}
hope this helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
S

Serg Matvienko

Hi Mohamed,



Thank you very much for your help, but unfortunately it doesn't work this
way. Maybe you could advise me a good book about window form's data grids. I
have seen lots of book about web data grids, but never about window form's
ones.



Sincerely,

Serg
 
R

Radovan Radic

Hi Serg,

Try this

public class NewGrid : DataGrid
{
public NewGrid()
{
this.ReadOnly = true;
}

protected override void OnCurrentCellChanged(EventArgs e)
{
this.Select(this.CurrentRowIndex);
}

protected override void OnVisibleChanged(EventArgs e)
{
if (this.CurrentRowIndex > -1)
this.Select(this.CurrentRowIndex);
}
}

If you dont want to see focused EditBox in the Grid's columns, you should
inherit DataGridTextBoxColumn and override Edit method

protected override void Edit(System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string
instantText, bool cellIsVisible)
{
if (this.ReadOnly)
return;
else
base.Edit(source, rowNum, bounds, readOnly, instantText,
cellIsVisible);
}

HTH,
Radovan
 
M

Mohamoss

Hi Serg
Here you are some links that would enough to get you acquainted with
winForms datagrids
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp (simple question and
answer form )
http://www.codeproject.com/cs/miscctrl/#Grid+controls ( some source code
examples with illustration )
about you problem again what you need to do is
" Select your dataGrid in the design window
" Form the property pane , select the event tab
" Double click the event Navigate
" Add the handler like so :
private void dataGrid1_Navigate(object sender,
System.Windows.Forms.NavigateEventArgs ne)
{
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top