1

I Have An API And That API Give Me A Jason Of Some Lists And I Show That In My DataGridView I Want To Set A Check Box Column To My DataGridView For Selecting A Row Of A DataGridView Easier.

That's My Answer From API And Set To DataGridView

var WorkListFromApis = serializer.Deserialize<List<Sysmexxp300WorkListFromApi>>(json.ToString());
                    dgv_tests.DataSource = WorkListFromApis;

That's My Sysmexxp300WorkListFromApi Class

 public class Sysmexxp300WorkListFromApi  //Model For WorkList OF Sysmex Xp300
    {
        public Int64 Id_ReceptionDetail { get; set; }
        public string PatientName { get; set; }
        public string MasterPriorityName { get; set; }
        public string DetailPriorityName { get; set; }
        public int Code_Patient { get; set; }
        public string CustomCode { get; set; }
        public string WBC { get; set; }
        public string RBC { get; set; }
        public string HGB { get; set; }
        public string HCT { get; set; }

    }

How Can I Add Check Box To Each Row ??

3
  • Add a bool property to the class. Commented Apr 16, 2022 at 10:36
  • @Jimi I don't want to do that i want a dynamic check box column i have so many classes Commented Apr 16, 2022 at 10:39
  • Then build a new DataGridViewCheckBoxColumn and add it to the grid's Columns collection, specifying its visual position and a name (it may be useful to get the Column by name when needed). Commented Apr 16, 2022 at 10:41

1 Answer 1

1

If you meant to add a column with checkboxes:

DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "X";
checkColumn.HeaderText = "X";
checkColumn.Width = 50; // or any other value as you wish
checkColumn.ReadOnly = false;
checkColumn.FillWeight = 10;

dataGridView1.Columns.Add(checkColumn);

You also may need to asign TrueValue & FalseValue to it:

checkColumn.FalseValue = "0";
checkColumn.TrueValue = "1";

To use DataGridViewColumn.DisplayIndex Property Check this link

For more and deep information, this may help you How to make a Checkbox with text cell in a datagridview

Sign up to request clarification or add additional context in comments.

1 Comment

Add a reference to the DisplayIndex Property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.