Hi all,
I am working in VS 2005 and have a datagridview that correctly displays data through an ODBC connection. each column in the datagridview is then displayed in a textbox which the user can edit.
However my problem is that the fields in the datagridview are 40 characters long and say the data is 5 characters long, the remaining 35 characters are padded out with white space.
How can this be removed so that when the user clicks to edit a textbox field, the cursor will appear at 5th character and not the 40th?
I have tried trimming the data with the 'trim' function but it doesn't appear to work.
Here is my code:
try
{
<connection>.Open();
<dataset>.Clear();
<dataadapter>.Fill(<dataset>, "tablename");
<datagrid>.DataSource = <dataset>.Tables["tablename"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
<connection>.Close();
<connection>.Dispose();
}
this.<textbox1>.DataBindings.Add("text", <Dataset>.Tables["tablename"], "column1".Trim());
this.<textbox2>.DataBindings.Add("text", <Dataset>.Tables["tablename"], "column2".Trim());
this.<textbox3>.DataBindings.Add("text", <Dataset>Tables["tablename"], "column3".Trim());
}
Any help would be greatly appreciated..
Thanks
Ross
I am working in VS 2005 and have a datagridview that correctly displays data through an ODBC connection. each column in the datagridview is then displayed in a textbox which the user can edit.
However my problem is that the fields in the datagridview are 40 characters long and say the data is 5 characters long, the remaining 35 characters are padded out with white space.
How can this be removed so that when the user clicks to edit a textbox field, the cursor will appear at 5th character and not the 40th?
I have tried trimming the data with the 'trim' function but it doesn't appear to work.
Here is my code:
try
{
<connection>.Open();
<dataset>.Clear();
<dataadapter>.Fill(<dataset>, "tablename");
<datagrid>.DataSource = <dataset>.Tables["tablename"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
<connection>.Close();
<connection>.Dispose();
}
this.<textbox1>.DataBindings.Add("text", <Dataset>.Tables["tablename"], "column1".Trim());
this.<textbox2>.DataBindings.Add("text", <Dataset>.Tables["tablename"], "column2".Trim());
this.<textbox3>.DataBindings.Add("text", <Dataset>Tables["tablename"], "column3".Trim());
}
Any help would be greatly appreciated..
Thanks
Ross