How to get the column width at runtime?
Hello,
I am using sfDataGrid in winforms App and I have a requirement to set width and left position of textboxes in relation to specific columns in sfDataGrid. I have method to implement this requirement but anytime I run it throws an exception: "Value was either too large or too small for an int32"
I realised during code walk through that the these columns values were : NaN. The method run at
sfDataGrid1_SizeChanged event.
The method is shown below:
private void TotalsPlacement()
{
var leftPos = sfDataGrid1.Columns[0].Width + sfDataGrid1.Columns[1].Width +
sfDataGrid1.Columns[2].Width + sfDataGrid1.Columns[3].Width + sfDataGrid1.Columns[4].Width
+ sfDataGrid1.Columns[5].Width + sfDataGrid1.Columns[6].Width;
txtDebit.Left = Convert.ToInt32(leftPos);
txtCredit.Left = txtCredit.Left + Convert.ToInt32(sfDataGrid1.Columns[7].Width);
txtCredit.Width = Convert.ToInt32(sfDataGrid1.Columns[7].Width);
txtBalance.Left = txtCredit.Left;
txtBalance.Width = txtCredit.Width;
}
Thanks in advance for your usual assistance
Best regards,
Paul Aziz
|
var leftPos = sfDataGrid1.Columns[0].ActualWidth + sfDataGrid1.Columns[1].ActualWidth + sfDataGrid1.Columns[2].ActualWidth +
sfDataGrid1.Columns[3].ActualWidth + sfDataGrid1.Columns[4].ActualWidth + sfDataGrid1.Columns[5].ActualWidth + sfDataGrid1.Columns[6].ActualWidth;
textBox1.Left = Convert.ToInt32(leftPos);
textBox1.Left = textBox1.Left + Convert.ToInt32(sfDataGrid1.Columns[6].ActualWidth);
textBox1.Width = Convert.ToInt32(sfDataGrid1.Columns[6].ActualWidth);
textBox2.Left = textBox1.Left;
textBox2.Width = textBox1.Width; |
Hi Arulpriya,
Thanks for the reply.
Your suggestion worked like magic. I am truly grateful.
This is just by way of information. My method was not producing desired result when it was being called from sfDataGrid1_SizeChanged event. So I changed the event to Form_SizeChanged event and that is it.
Best regards
Paul Aziz
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.
Regards,
Vijayarasan S
- 3 Replies
- 3 Participants
-
PA Paul
- Sep 19, 2021 05:21 PM UTC
- Sep 22, 2021 04:18 PM UTC