Hi ,
I am struggling to set the alignment of the text inside the datagridview column when it is done . I am using
public CustomDataGridView()
{
InitializeComponent();
// this.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
but found out that since my customdatagridview doesn't have columns initially and i add the columns only on form , the above code throws error .
so just for checking , i add the code in form load
public Form1()
{
InitializeComponent();
this.customDataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
but it gave me a weird result . as although i instruct the column1(in oneditingcontrolshowing) to start typing from right to left (see below code ) , the system weirdly starts typing from the left to right only and that too only for column1
protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
{
TextBox textBox = e.Control as TextBox; // var tbox = (TextBox)e.Control;
if (textBox != null)
{
disableSelectWindow = new DisableSelectWindow(textBox);
textBox.ContextMenuStrip = new ContextMenuStrip(); // disable contect menu
}
// except starting column ie. 0 , all columns must type from right to left
if (this.CurrentCell.ColumnIndex > 0 && this.CurrentCell.RowIndex >= 0)
{
textBox.RightToLeft = RightToLeft.Yes;
textBox.TextAlign = HorizontalAlignment.Right;
}
base.OnEditingControlShowing(e);
}
Now the reason for not defining the column names and column count in the declaration of customdatagridview is that , this custom datagridview would be used in multiple Forms and each time it would have different number of columns but one thing is sure that except column0 . every column will starts typing from right to left and after that must aligned to right side only . Below is the link for my github project pls correct my code behaviour .
https://github.com/RahulKumarcool/Rahulkumar