Search code examples
vb.netsortingdatagridcell

datagrid cell validation and automatic sort - VB.NET


I have a problem...

I need a VB code which validate cell (ID) - (I used event CellValidating),

this value must be unique in datagrid... and if this value of cell is uniqe, then sort rows in datagrid by the ID column.

Example, datagrid is:

ID          Name                
1           First
3           third

And if I enter in the ID value 3, then popup Messagebox.Show ("Error")...

But, if I enter value 2 in the column ID, then the datagrid must sort automatically

Is this good for sorting -> DataGridViewColumnSortMode.Automatic ??

Thanks


Solution

  • Should be able to use a simple If Then statement to get this done. This outline should get you going in the right direction.

    If datagrid.ID = "your input" Then
    msgbox("This ID already exhists")
    ElseIf
    'code to add to datagrid
    'code to re-sort grid
    EndIF