How to set rightToLeft=Yes.

Oct 1, 2010 at 3:23 PM

Hello.

I see that there is RightToLeft property on Grid.

In original-code (GridVirtual) there is no set method, and the get method returns RightToLeft.No.

I have changed the code to followings, but still doesn't work (when I change RightToLeft = Yes, the grid isn't fliped from right-to-left as DataGridView, i.e., does.

What is wrong in my code ?

[Browsable(true)]  

[DefaultValue(RightToLeft.No)]

// [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

 public override RightToLeft RightToLeft

{

 

get { return base.RightToLeft; }

 

set { base.RightToLeft = value; }

}

 

Thanks :)

Oct 2, 2010 at 9:20 AM

I would like a solution for that.

One of solution, I have thought about is to change the bound rectangle of the cell on each cell insert.

But where is the code for the bound rectangle?

I need a sample, please.

 

Thanks :)

Oct 2, 2010 at 7:15 PM

I hope I find answers in this forum for my questions ...

Didn't anyone solve the problem for RightToLeft.

I have change some of the code to do that.

First : I have deleted the property RightToLeft on Grid.

I have changed getLeft on ColumnsBase like this and OnRangePaint on GridVirtual.

 Please help. I have spent to much time to resolve the problem.

 

 Thanks :)

public int GetLeft(int column)

{

 

// *** Eitan *** Check the rightToLeft ...
 

 

int actualFixedColumns = Math.Min(Grid.FixedColumns, Count);

 

int left = 0;

 

RightToLeft actualRTL;

 

// *** Eitan ***
 

actualRTL =

this.Grid.RightToLeft; // what if = inherited ?
 

 

if (actualRTL == RightToLeft.Yes)

{

 

// check until the one before last column.
 

 

//for (int i = 0; i < Count; i++)
 

 

//{
 

 

// left += GetWidth(i);
 

 

//}
 

 

//left -= GetWidth(column);
 

left =

this.Grid.Width - GetWidth(0);

}

 

// *** Eitan - end block
 

 

//Calculate fixed left cells
 

 

for (int i = 0; i < actualFixedColumns; i++)

{

 

if (actualRTL == RightToLeft.Yes)

{

 

if (i == column)

 

return left;

left -= GetWidth(i);

}

 

else
 

{

 

if (i == column)

 

return left;

left += GetWidth(i);

}

}

 

int? relativeColumn = FirstVisibleScrollableColumn;

 

if (relativeColumn == null)

relativeColumn = Count;

 

if (relativeColumn == column)

 

return left;

 

else if (relativeColumn < column)

{

 

for (int i = relativeColumn.Value; i < Count; i++)

{

 

if (actualRTL == RightToLeft.Yes)

{

 

if (i == column)

 

return left;

left -= GetWidth(i);

}

 

else
 

{

 

if (i == column)

 

return left;

left += GetWidth(i);

}

}

}

 

else if (relativeColumn > column)

{

 

for (int i = relativeColumn.Value - 1; i >= 0; i--)

{

 

if (actualRTL == RightToLeft.Yes)

{

left += GetWidth(i);

 

if (i == column)

 

return left;

}

 

else
 

{

left -= GetWidth(i);

 

if (i == column)

 

return left;

}

}

}

 

throw new IndexOutOfRangeException();

}

================================

 

 RangePaint :

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

protected virtual void OnRangePaint(RangePaintEventArgs

e)

{

 

Rectangle

drawRectangle = RangeToRectangle(e.DrawingRange);

System.Drawing.Drawing2D.

GraphicsState

state = e.GraphicsCache.Graphics.Save();

 

try

{

e.GraphicsCache.Graphics.SetClip(drawRectangle);

 

int

top = drawRectangle.Top;

 

int

width;

 

int

height;

 

foreach (var r in

m_Rows.HiddenRowsCoordinator.LoopVisibleRows(e.DrawingRange.Start.Row, e.DrawingRange.End.Row - e.DrawingRange.Start.Row))

 

//for (int r = e.DrawingRange.Start.Row; r <= e.DrawingRange.End.Row; r++)

{

 

if (Rows.IsRowVisible(r) == false

)

 

throw new SourceGridException("Incorrect internal state. This rows must have been visible"

);

height = Rows.GetHeight(r);

 

int

left;

 

if (this.RightToLeft == RightToLeft.Yes)

// *** Eitan ***

{

left =

this

.Width;

 

for (int

i = 0; i < e.DrawingRange.Start.Column; i++)

left -= Columns.GetWidth(i);

// for (int i = 0; i < Columns.Count - 1; i++)

// left += Columns.GetWidth(i);

}

 

else

left = drawRectangle.Left;

 

for (int

c = e.DrawingRange.Start.Column; c <= e.DrawingRange.End.Column; c++)

{

width = Columns.GetWidth(c);

 

if (this.RightToLeft == RightToLeft.Yes)

// *** Eitan ***

left -= width;

 

if (Columns.IsColumnVisible(c) == false

)

 

continue

;

 

Position position = new Position

(r, c);

Cells.

ICellVirtual

cell = GetCell(position);

 

if (cell != null

)

{

 

Rectangle drawRect = new Rectangle

(left, top, width, height);

 

//Draw the cell only if inside the ClipRectangle

 

if

(e.GraphicsCache.ClipRectangle.IsEmpty ||

e.GraphicsCache.ClipRectangle.IntersectsWith(drawRect))

{

 

CellContext cellContext = new CellContext(this

, position, cell);

PaintCell(e.GraphicsCache, cellContext, drawRect);

}

}

 

if (this.RightToLeft != RightToLeft.Yes)

// *** Eitan ***

left += width;

}

top += height;

}

 

//Draw the decorators

 

foreach (SourceGrid.Decorators.DecoratorBase dec in

Decorators)

{

 

if

(dec.IntersectWith(e.DrawingRange))

dec.Draw(e);

}

 

if (RangePaint != null

)

RangePaint(

this

, e);

}

 

finally

{

e.GraphicsCache.Graphics.Restore(state);

}

}

Coordinator
Oct 4, 2010 at 8:21 AM

See example 44, it is specifcally made for right to left support

Oct 6, 2010 at 9:45 AM

Have you looked that sample of 44?

- it is not a real right-to-left (For Hebrew and rightToLeft language, and on title : not yet completed - It should not do mirroring, when you see "b" as "d").

If you look deeper in code, you will see that in gridVirtual.cs the following code :

(The code returns : return RightToLeft.No all the time ...

So, If I cannot set RightToLeft to true, and even if I set it, and even I remark the following code - the order of the columns stay the same).

 

Anyway, I have spent days to build my own right-to-left support with swet and teers, based on the sourcegrid, with success.

Thanks, anyway.

 /// <summary>  /// Hide the RightToLeft property and returns always No. 

 

/// </summary>

[

Browsable(false)]

[

DefaultValue(RightToLeft.No)]

[

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

 

public override RightToLeft RightToLeft

{

 

get { return RightToLeft.No; }

 

set { }

}

 

 

 

Coordinator
Oct 7, 2010 at 8:36 AM

If you have mode some improvements to SourceGrid, you can send your changes as a patch against most current SourceGrid code, and we would integrate that

Oct 10, 2010 at 6:44 AM

How can I do that?

Coordinator
Oct 11, 2010 at 10:52 AM

just update to newest tip (http://bitbucket.org/dariusdamalakas/sourcegrid), and use hg export command to make a patch.

then attach that patch as a file here : http://sourcegrid.codeplex.com/SourceControl/UploadPatch.aspx