1

I'm importing the excel files using import button and displaying them in the datagridview. Now when i click at apply button, i want the first letter of the row values(highlighted in the attached image) to be capitalized (there can be multiple rows/values).

eg: peter joe ===> Peter Joe

How can i edit these values.

I'm a beginner, would be great if anyone can help with this.

h3r
  • 43
  • 1
  • 1
  • 7
  • 2
    This might help you: https://stackoverflow.com/questions/913090/how-to-capitalize-the-first-character-of-each-word-or-the-first-character-of-a – Joeri E Sep 15 '20 at 06:09
  • You can loop over your datagrid view excluding the first row and first column and then apply the code from the link above. – Joeri E Sep 15 '20 at 06:16
  • @joerie "loop over the datagridview" - no, not for a bound grid. Stick to your MVC principles.. – Caius Jard Sep 15 '20 at 07:14

1 Answers1

1

This isnt really anything to do with editing excel row values (per the title) but..

You have an apply button click event handler that enumerates the datatable and sets the values:

private void applyButton_Click(object sender, EventArgs e)
{
  TextInfo info = CultureInfo.CurrentCulture.TextInfo;
  DataTable dt = datagridview1.DataSource as DataTable;

  foreach(DataRow r in dt.Select("[SET 1] = 'CUSTOMER'"))
    for(int x = 1; x < r.ItemArray.Length; x++)
      r[x] = info.ToTitleCase(r[x].ToString().ToLower());
}

enter image description here

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • If i try this code, How do i display the updated table in datagridview after clicking Apply button – h3r Sep 15 '20 at 06:34
  • Above code is working(tried at console level)... but not getting updated in the table after clicking at Apply button.. what shout i do to update the table in grid view – h3r Sep 15 '20 at 06:56
  • When a datagridview is bound to a datatable you update the data in the table and the grid changes automatically. Be sure you don't have an active edit open on the relevant row on the grid – Caius Jard Sep 15 '20 at 07:13
  • (See the added animation - there is no other hidden code here; the first frames show the complete program which is purely creating and filling a DT, binding it to grid, then the code I gave above) – Caius Jard Sep 15 '20 at 08:56