How do I align text for a single subitem in a ListView using C#?

后端 未结 6 981
离开以前
离开以前 2021-01-18 08:57

I wasn\'t able to find an answer anywhere about this seemingly simple topic: is it possible to align text of a single subitem in a WinForms ListView control?

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 09:24

    Put the ListView control on form and name it "listV1" and add and edit 4 columns. Also define one Index. Then, format column "0" without the header and with Width=0. That way column 0 will be invisible. Then you can format other columns as you wish (left, center,right) which are all visible.

    ListView listV1 = new ListView();
    uint Index = 0;   
    string[] Split_Message = Some_Message.Split(','); // split it to comma...
    ListViewItem L = new ListViewItem(""); //... to column "0" assign empty string...
    L.SubItems.Add(Index.ToString() + "."); //... than fill the first fild in the row. It is number converted to string...
    L.SubItems.Add(Split_Message[0]); //... then first string from buffer...
    L.SubItems.Add(Split_Message[1]); //... again, second string from buffer etc. ...
    listV1.Items.Add(L); //... and at the end write all of this into the first row.
    Indexx++; // Next number.
    

提交回复
热议问题