How can I hihglight the whole row of DataGrid ?

  • Thread starter Thread starter Serg Matvienko
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Back
Top